迅睿開源框架是一款PHP8高性能·簡單易用的PHP開源開發(fā)框架, 基于MIT開源許可協(xié)議發(fā)布,不限制商業(yè)使用,以多端互聯(lián)為設計理念, 支持的微信公眾號、小程序、APP客戶端、移動端網(wǎng)站、PC網(wǎng)站等多終端式管理系統(tǒng)。
業(yè)務經(jīng)理
微信掃描以上二維碼
028-61286886
技術咨詢
自定義函數(shù) 寫入讀取緩存,代碼如上圖,一直進入if內(nèi),大佬看看哪里有錯,if內(nèi)data有值
后臺沒開啟緩存么
回復@一休哥 后臺開啟了緩存功能,還是一樣的
我的可以緩存,這個本來就是緩存函數(shù)
回復@二開/定制/使用解答專家 每次運行都會 echo ‘---’ 這個代碼不是在 if 里面嗎,意思是每次都進 if 嗎?
只能說明你data本身就是空的
回復@二開/定制/使用解答專家
function vg_price($num){
$ci = &get_instance();
$name = 'ym-'.$num;
$data = $ci->get_cache_data($name);
if (!$data) {
echo "---";
$url = 'http://222.75.151.210:8085/webService/BaseManage/CORN_PRICE.asmx'; //接收xml數(shù)據(jù)的文件
$header[] = "Content-type: text/xml; charset=utf-8"; //定義content-type為xml,注意是數(shù)組
$xmlData = '
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:getPrice>
<tem:code>'.$num.'</tem:code>
</tem:getPrice>
</soapenv:Body>
</soapenv:Envelope>
';
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $xmlData);
$response = curl_exec($ch);
if(curl_errno($ch)){
printcurl_error($ch);
}
curl_close($ch);
$data = strip_tags($response);
$ci->set_cache_data($name, $data, 3600);
return $data;
您測試一下 參數(shù)為 1001
function vg_price($num){ $ci = &get_instance(); $name = 'ym-'.$num; $data = $ci->get_cache_data($name); if (!$data) { echo "---"; $data = 'test2123123123'; $ci->set_cache_data($name, $data, 3600); } return $data; }
這還不簡單的測試,如果任然進入if,就是系統(tǒng)沒有開啟緩存,或者cache權(quán)限不對
回復@掃地僧
多次訪問一直都是這樣
我的經(jīng)驗,1cache/file和cache/data能否可寫文件,2插件優(yōu)化里面是不是文件存儲緩存,3實在不行就檢查下程序版本是不是最新
后臺沒開啟緩存么
回復@一休哥 后臺開啟了緩存功能,還是一樣的
我的可以緩存,這個本來就是緩存函數(shù)
回復@二開/定制/使用解答專家 每次運行都會 echo ‘---’ 這個代碼不是在 if 里面嗎,意思是每次都進 if 嗎?
只能說明你data本身就是空的
回復@二開/定制/使用解答專家
function vg_price($num){
$ci = &get_instance();
$name = 'ym-'.$num;
$data = $ci->get_cache_data($name);
if (!$data) {
echo "---";
$url = 'http://222.75.151.210:8085/webService/BaseManage/CORN_PRICE.asmx'; //接收xml數(shù)據(jù)的文件
$header[] = "Content-type: text/xml; charset=utf-8"; //定義content-type為xml,注意是數(shù)組
$xmlData = '
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">
<soapenv:Header/>
<soapenv:Body>
<tem:getPrice>
<tem:code>'.$num.'</tem:code>
</tem:getPrice>
</soapenv:Body>
</soapenv:Envelope>
';
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER,$header);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $xmlData);
$response = curl_exec($ch);
if(curl_errno($ch)){
printcurl_error($ch);
}
curl_close($ch);
$data = strip_tags($response);
$ci->set_cache_data($name, $data, 3600);
}
return $data;
}
您測試一下 參數(shù)為 1001
function vg_price($num){ $ci = &get_instance(); $name = 'ym-'.$num; $data = $ci->get_cache_data($name); if (!$data) { echo "---"; $data = 'test2123123123'; $ci->set_cache_data($name, $data, 3600); } return $data; }這還不簡單的測試,如果任然進入if,就是系統(tǒng)沒有開啟緩存,或者cache權(quán)限不對
回復@掃地僧
多次訪問一直都是這樣
我的經(jīng)驗,1cache/file和cache/data能否可寫文件,2插件優(yōu)化里面是不是文件存儲緩存,3實在不行就檢查下程序版本是不是最新