From f124a21f050fbbd4abe7011e687724131c8c2cb5 Mon Sep 17 00:00:00 2001 From: Marc Neuhaus Date: Mon, 12 Mar 2018 11:40:25 +0100 Subject: [PATCH] improve timeout handling --- Classes/Service/ApiClient.php | 10 ++++++++-- ext_conf_template.txt | 5 +++++ ext_localconf.php | 7 +++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 ext_conf_template.txt diff --git a/Classes/Service/ApiClient.php b/Classes/Service/ApiClient.php index 7f93ae0..8eaf4cb 100644 --- a/Classes/Service/ApiClient.php +++ b/Classes/Service/ApiClient.php @@ -42,6 +42,11 @@ class ApiClient */ protected static $lastResponse = []; + /** + * @var array + */ + protected $extensionConfiguration = []; + /** * @param Server $server */ @@ -57,6 +62,7 @@ public function __construct($server) } self::$sessionPool[] = $this; $this->initializeCreateMasks(); + $this->extensionConfiguration = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['fourallportal']); } public function login() @@ -196,8 +202,8 @@ public function saveDerivate($filename, $objectId, $usage = null) $temporaryHeaderbufferName = tempnam(sys_get_temp_dir(), 'header-buff' . $objectId); $headerBuff = fopen($temporaryHeaderbufferName, 'w+'); - curl_setopt($ch, CURLOPT_TIMEOUT, 0); - curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60); + curl_setopt($ch, CURLOPT_TIMEOUT, (int)$this->extensionConfiguration['clientConnectTimeout']); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, (int)$this->extensionConfiguration['clientTransferTimeout']); curl_setopt($ch, CURLOPT_FILE, $fp); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_WRITEHEADER, $headerBuff); diff --git a/ext_conf_template.txt b/ext_conf_template.txt new file mode 100644 index 0000000..f275c86 --- /dev/null +++ b/ext_conf_template.txt @@ -0,0 +1,5 @@ +# cat=basic/timeout/10; type=int; label=Client request timeout;Number of seconds the API client will wait for the remote server to respond. Zero means infinite wait. +clientConnectTimeout = 10 + +# cat=basic/timeout/10; type=int; label=Client transfer timeout;Number of seconds the API client will wait for the remote server to finish transferring data. Zero means infinite wait. +clientTransferTimeout = 60 diff --git a/ext_localconf.php b/ext_localconf.php index eb2c659..fb7e7f4 100644 --- a/ext_localconf.php +++ b/ext_localconf.php @@ -3,6 +3,13 @@ die ('Access denied.'); } +if (!isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['fourallportal'])) { + $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['fourallportal'] = [ + 'clientConnectTimeout' => 10, + 'clientTransferTimeout' => 60, + ]; +} + \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerTypeConverter(\Crossmedia\Fourallportal\TypeConverter\FileReferenceTypeConverter::class); \TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerTypeConverter(\Crossmedia\Fourallportal\TypeConverter\ComplexTypeConverter::class);