ubuntu系統(tǒng)
Warning: file_put_contents(/xxxx/log//17-03-22.txt): failed to open stream: Too many open files in /xxx/common/function.php on line 323
這是方法是寫(xiě)日志,用的是file_put_contents方法,按理說(shuō)寫(xiě)完日志就關(guān)掉了文件連接了,而我的work就看了3個(gè)進(jìn)程,就導(dǎo)致了這個(gè)問(wèn)題,請(qǐng)問(wèn)如何解決?
調(diào)試發(fā)現(xiàn)是curl_init造成的,但是有關(guān)閉,系統(tǒng)卻一直保持連接
protected function _wget($url, $post_data = null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
if ($post_data) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
}
$response = curl_exec($ch);
if ($response === false) {
system_log('獲取遠(yuǎn)程數(shù)據(jù)失敗:' . curl_error($ch));
curl_close($ch);
return false;
}
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http_code == 200) {
$ret = json_decode($response, true);
if ($ret) {
return $ret;
}
system_log('獲取遠(yuǎn)程數(shù)據(jù)返回異常內(nèi)容:' . $response);
} else {
system_log('獲取遠(yuǎn)程數(shù)據(jù)返回異常狀態(tài)碼:' . $http_code . ',返回內(nèi)容為:' . $response);
return false;
}
}
http://php.net/manual/en/function.curl-setopt.php
這里有curl選項(xiàng),應(yīng)該有強(qiáng)制關(guān)閉復(fù)用鏈接的選項(xiàng),找下