我在禁用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()
并不意味着等待资源正确响应?
答案 0 :(得分:0)
默认情况下,超时非常短(类似于0.01秒),因为有时请求失败,基本上,wp_cron可以在下次再次尝试。你似乎把它改成了很长的间隔,因此它是显而易见的。看看this Trac thread。如果你有define('WP_DEBUG',true);
,你会一直看到这个。我想你可能会担心没什么重要的。它真的会造成麻烦吗?对我自己来说,我从来没有注意到它的问题。