From 9679fb154ae6cc67b049ed16e0e9d85d27cb0f7e Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Fri, 14 Jun 2019 12:31:14 +1000 Subject: [PATCH] dev/core#1035 Add in new setting http_timeout to set how long in seconds should HTTP requests last for to fix dev/core#1035 Handle situations where a 0 timeout is passed in Remove from form Update variable name as per EIleen --- CRM/Utils/Check/Component.php | 10 +++++++--- settings/Core.setting.php | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CRM/Utils/Check/Component.php b/CRM/Utils/Check/Component.php index 9b2a02938c..f07f2923fc 100644 --- a/CRM/Utils/Check/Component.php +++ b/CRM/Utils/Check/Component.php @@ -62,16 +62,20 @@ abstract class CRM_Utils_Check_Component { * Check if file exists on given URL. * * @param string $url - * @param float $timeout + * @param float|bool $timeoutOverride * * @return bool */ - public function fileExists($url, $timeout = 0.50) { + public function fileExists($url, $timeoutOverride = FALSE) { + // Timeout past in maybe 0 in which case we should still permit it (0 is infinite). + if (!$timeoutOverride && $timeoutOverride !== 0) { + $timeoutOverride = (float) Civi::settings()->get('http_timeout'); + } $fileExists = FALSE; try { $guzzleClient = new GuzzleHttp\Client(); $guzzleResponse = $guzzleClient->request('GET', $url, array( - 'timeout' => $timeout, + 'timeout' => $timeoutOverride, )); $fileExists = ($guzzleResponse->getStatusCode() == 200); } diff --git a/settings/Core.setting.php b/settings/Core.setting.php index 77dc4cce90..2b8bdf3e04 100644 --- a/settings/Core.setting.php +++ b/settings/Core.setting.php @@ -1062,4 +1062,23 @@ return [ 'description' => ts('Acceptable Mime Types that can be used as part of file urls'), 'help_text' => NULL, ], + 'http_timeout' => [ + 'group_name' => 'CiviCRM Preferences', + 'group' => 'core', + 'name' => 'http_timeout', + 'type' => 'Integer', + 'quick_form_type' => 'Element', + 'html_type' => 'text', + 'html_attributes' => [ + 'size' => 2, + 'maxlength' => 3, + ], + 'default' => 5, + 'add' => '5.15', + 'title' => ts('HTTP request timeout'), + 'is_domain' => 1, + 'is_contact' => 0, + 'description' => ts('How long should HTTP requests through Guzzle application run for in seconds'), + 'help_text' => ts('Set the number of seconds http requests should run for before terminating'), + ], ]; -- 2.25.1