我在一臺服務器上用wordpress WP_Cron問題,禁用了cUrl,基本上調用了cron塊服務器,我想知道爲什麼會發生這種情況,以及它是否與我的web服務器的某些配置有關。即使我將它設置爲非阻塞,fopen也會阻止wordpress。這是我的服務器故障嗎?
這是代碼
$arrContext = array('http' =>
array(
'method' => strtoupper($r['method']),
'user_agent' => $r['user-agent'],
'max_redirects' => $r['redirection'] + 1, // See #11557
'protocol_version' => (float) $r['httpversion'],
'header' => $strHeaders,
'ignore_errors' => true, // Return non-200 requests.
'timeout' => $r['timeout'],// here i have 10
'ssl' => array(
'verify_peer' => $ssl_verify,
'verify_host' => $ssl_verify
)
)
);
$proxy = new WP_HTTP_Proxy();
if ($proxy->is_enabled() && $proxy->send_through_proxy($url)) {
$arrContext['http']['proxy'] = 'tcp://' . $proxy->host() . ':' . $proxy->port();
$arrContext['http']['request_fulluri'] = true;
// We only support Basic authentication so this will only work if that is what your proxy supports.
if ($proxy->use_authentication())
$arrContext['http']['header'] .= $proxy->authentication_header() . "\r\n";
}
if (! empty($r['body']))
$arrContext['http']['content'] = $r['body'];
$context = stream_context_create($arrContext);
if (!WP_DEBUG)
$handle = @fopen($url, 'r', false, $context);
else
$handle = fopen($url, 'r', false, $context);
error_log('after');
if (! $handle)
return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url));
$timeout = (int) floor($r['timeout']);
$utimeout = $timeout == $r['timeout'] ? 0 : 1000000 * $r['timeout'] % 1000000;
stream_set_timeout($handle, $timeout, $utimeout);
if (! $r['blocking']) {
stream_set_blocking($handle, 0);
fclose($handle);
return array('headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array());
}
如果我設置的10錯誤日誌超時從不打印呼叫到wp_cron和得到這個錯誤,而不是
PHP的警告:FOPEN( http://localhost/wordpress/wp-cron.php?doing_wp_cron = 1350494198.1313750743865966796875)[function.fopen]:無法打開流:HTTP請求失敗!在C:?\程序文件(x86)\ Zend的\ Apache2的\ htdocs中\ WordPress的\ WP-包括\類http.php上線925
這是我的服務器上的一些配置導致此我認爲調用fopen()
並不意味着等待資源回覆正確嗎?
是的,我知道,但基本上fopen不允許非阻塞呼叫。但是fsocket呢。閱讀此曲目http://core.trac.wordpress.org/ticket/18738 –