Skip to content

Commit

Permalink
improve timeout handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Neuhaus committed Mar 12, 2018
1 parent 3ae353d commit f124a21
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Classes/Service/ApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ class ApiClient
*/
protected static $lastResponse = [];

/**
* @var array
*/
protected $extensionConfiguration = [];

/**
* @param Server $server
*/
Expand All @@ -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()
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions ext_conf_template.txt
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit f124a21

Please sign in to comment.