我在禁用 cUrl 的服务器上遇到 wordpress WP_Cron 问题,基本上调用 cron 会阻止服务器,我想知道为什么会发生这种情况,以及它是否与我的网络服务器的某些配置有关。
这是代码
$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请求失败!在第 925 行的 C:\Program Files (x86)\Zend\Apache2\htdocs\wordpress\wp-includes\class-http.php
是不是我的服务器上的某些配置导致了这种情况?我认为调用fopen()
并不意味着等待资源响应对吗?