3
我很新使用cURL。有沒有簡單的方法來緩存cURL JSON請求的響應?這是我的要求...如何在PHP中緩存JSON cURL響應?
<?php
error_reporting(E_ALL);
$url = "[JSON api call url]";
$timeout = 40;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
$str = curl_exec($ch);
curl_close($ch);
$data = array();
if ($str !== false) {
$data = json_decode($str);
}
?>
謝謝!
[從服務器高速緩存CURL JSON數據]的可能重複(http://stackoverflow.com/questions/6977563/caching-curl-json-data-from-server) –