cURL 连接超时。
这种情况最普遍,这里的超时并不是完全不可连接,而是因为网络状况或其它原因数据传输缓慢,超过连接的时间限制导致传输中断引起的错误。
不论是何种原因导致连接超时,都可以通过增加超时限制来解决此问题。但 URL 完全不可访问此方法是解决不了的。
首先将 WordPress 中的 wp_Http request() 函数连接超时限制修改成15秒或更大值。将以下代码添加至functions.php文件中,或使用代码片段插件添加。
- //调整 wp-includes/http.php 超时限制值以解决服务器响应缓慢的问题
- add_filter( 'http_request_args', 'bal_http_request_args', 100, 1 );
- function bal_http_request_args( $r ) //called on line 237
- {
- $r['timeout'] = 15; //单位:秒
- return $r;
- }
- add_action( 'http_api_curl', 'bal_http_api_curl', 100, 1 );
- function bal_http_api_curl( $handle ) //called on line 1315
- {
- curl_setopt( $handle, CURLOPT_CONNECTTIMEOUT, 15 );
- curl_setopt( $handle, CURLOPT_TIMEOUT, 15 );
- }
然后将php.ini中 default_socket_timeout 的值修改为300,默认60。
通过以上调整后,“cURL error 28”错误应该彻底消失了。