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) –