From d852afb9e9fa92bd094c2175bf2f34f66469f9c5 Mon Sep 17 00:00:00 2001 From: Andrew Ozz Date: Sat, 16 Aug 2008 05:38:57 +0000 Subject: [PATCH] Disable fsockopen for 12 hours if it fails. Props jacobsantos, fixes #7514 git-svn-id: https://develop.svn.wordpress.org/trunk@8654 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-includes/http.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/wp-includes/http.php b/wp-includes/http.php index ad67682346..0b356d1413 100644 --- a/wp-includes/http.php +++ b/wp-includes/http.php @@ -125,10 +125,10 @@ class WP_Http { if ( is_null($working_transport) ) { if ( true === WP_Http_ExtHttp::test() && apply_filters('use_http_extension_transport', true) ) $working_transport[] = new WP_Http_ExtHttp(); - else if ( true === WP_Http_Fsockopen::test() && apply_filters('use_fsockopen_transport', true) ) - $working_transport[] = new WP_Http_Fsockopen(); else if ( true === WP_Http_Streams::test() && apply_filters('use_streams_transport', true) ) $working_transport[] = new WP_Http_Streams(); + else if ( true === WP_Http_Fsockopen::test() && apply_filters('use_fsockopen_transport', true) ) + $working_transport[] = new WP_Http_Fsockopen(); } return $working_transport; @@ -201,7 +201,7 @@ class WP_Http { } if ( isset($r['headers']['User-Agent']) ) { - $r['user-agent'] = $headers['User-Agent']; + $r['user-agent'] = $r['headers']['User-Agent']; unset($r['headers']['User-Agent']); } @@ -463,11 +463,21 @@ class WP_Http_Fsockopen { if ( true === $secure_transport ) $error_reporting = error_reporting(0); + $startDelay = time(); + 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'] ); + $endDelay = time(); + + // If the delay is greater than the timeout then fsockopen should't be + // used, because it will cause a long delay. + $elapseDelay = ($endDelay-$startDelay) > $r['timeout']; + if ( true === $elapseDelay ) + add_option( 'disable_fsockopen', $endDelay, null, true ); + if ( false === $handle ) return new WP_Error('http_request_failed', $iError . ': ' . $strError); @@ -544,6 +554,9 @@ class WP_Http_Fsockopen { * @return boolean False means this class can not be used, true means it can. */ function test() { + if ( false !== ($option = get_option( 'disable_fsockopen' )) && time()-$option < 43200 ) // 12 hours + return false; + if ( function_exists( 'fsockopen' ) ) return true;