From 1ef0029be8d863f6d829812b136cae2fbb2e80f4 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 13 Aug 2008 23:37:42 +0000 Subject: [PATCH] Adds checking for fsockopen to check for WP_DEBUG and silently drop warnings. Adds streams_set_timeout to fsockopen to help prevent long waits. Props santosj. see #7514 git-svn-id: http://svn.automattic.com/wordpress/trunk@8644 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/http.php | 16 +++++++++++++--- wp-includes/update.php | 3 +++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/wp-includes/http.php b/wp-includes/http.php index 0ba18c6518..86e3e9024d 100644 --- a/wp-includes/http.php +++ b/wp-includes/http.php @@ -463,11 +463,18 @@ class WP_Http_Fsockopen { if ( true === $secure_transport ) $error_reporting = error_reporting(0); - $handle = fsockopen($arrURL['host'], $arrURL['port'], $iError, $strError, $r['timeout'] ); + if ( !defined('WP_DEBUG') || ( defined('WP_DEBUG') && false === WP_DEBUG ) ) + $handle = @fsockopen($arrURL['host'], $arrURL['port'], $iError, $strError, $r['timeout'] ); + else + $handle = fsockopen($arrURL['host'], $arrURL['port'], $iError, $strError, $r['timeout'] ); if ( false === $handle ) return new WP_Error('http_request_failed', $iError . ': ' . $strError); + // WordPress supports PHP 4.3, which has this function. Removed sanity + // checking for performance reasons. + stream_set_timeout($handle, $r['timeout'] ); + $requestPath = $arrURL['path'] . ( isset($arrURL['query']) ? '?' . $arrURL['query'] : '' ); $requestPath = empty($requestPath) ? '/' : $requestPath; @@ -601,8 +608,9 @@ class WP_Http_Fopen { if (! $handle) return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url)); - if ( function_exists('stream_set_timeout') ) - stream_set_timeout($handle, $r['timeout'] ); + // WordPress supports PHP 4.3, which has this function. Removed sanity + // checking for performance reasons. + stream_set_timeout($handle, $r['timeout'] ); if ( ! $r['blocking'] ) { fclose($handle); @@ -726,6 +734,8 @@ class WP_Http_Streams { if ( ! $handle) return new WP_Error('http_request_failed', sprintf(__('Could not open handle for fopen() to %s'), $url)); + // WordPress supports PHP 4.3, which has this function. Removed sanity + // checking for performance reasons. stream_set_timeout($handle, $r['timeout'] ); if ( ! $r['blocking'] ) { diff --git a/wp-includes/update.php b/wp-includes/update.php index b1c162ad79..41d1d7b292 100644 --- a/wp-includes/update.php +++ b/wp-includes/update.php @@ -145,6 +145,9 @@ function wp_update_plugins() { $raw_response = wp_remote_request('http://api.wordpress.org/plugins/update-check/1.0/', $options); + if ( is_wp_error( $raw_response ) ) + return false; + if( 200 != $raw_response['response']['code'] ) { return false; }