8000 Allow to change remote media download timeout · generalstephen1/codebird-php@8891435 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8891435

Browse files
committed
Allow to change remote media download timeout
1 parent a04dbdb commit 8891435

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/codebird.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,11 @@ class Codebird
132132
*/
133133
protected $_connectionTimeout = 3000;
134134

135+
/**
136+
* Remote media download timeout
137+
*/
138+
protected $_remoteDownloadTimeout = 5000;
139+
135140
/**
136141
* Proxy
137142
*/
@@ -265,6 +270,18 @@ public function setConnectionTimeout($timeout)
265270
$this->_connectionTimeout = (int) $timeout;
266271
}
267272

273+
/**
274+
* Sets remote media download timeout in milliseconds
275+
*
276+
* @param int $timeout Remote media timeout in milliseconds
277+
*
278+
* @return void
279+
*/
280+
public function setRemoteDownloadTimeout($timeout)
281+
{
282+
$this->_remoteDownloadTimeout = (int) $timeout;
283+
}
284+
268285
/**
269286
* Sets the format for API replies
270287
*
@@ -1292,8 +1309,8 @@ protected function _getMultipartRequestFromParams($possible_files, $border, $par
12921309
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
12931310
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
12941311
// use hardcoded download timeouts for now
1295-
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 5000);
1296-
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 2000);
1312+
curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->_remoteDownloadTimeout);
1313+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $this->_remoteDownloadTimeout / 2);
12971314
// find files that have been redirected
12981315
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
12991316
// process compressed images
@@ -1307,7 +1324,7 @@ protected function _getMultipartRequestFromParams($possible_files, $border, $par
13071324
'http' => [
13081325
'method' => 'GET',
13091326
'protocol_version' => '1.1',
1310-
'timeout' => 5000
1327+
'timeout' => $this->_remote_download_timeout
13111328
],
13121329
'ssl' => [
13131330
'verify_peer' => false

0 commit comments

Comments
 (0)
0