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

Skip to content

Commit 256af7a

Browse files
committed
Allow to change remote media download timeout
Fix jublo#129
2 parents a04dbdb + e417545 commit 256af7a

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ codebird-php - changelog
99
+ #121 Allow for multiple parameters in templated methods
1010
by replacing preg_match with preg_match_all
1111
+ #134 Add support for compressed remote images
12+
+ #129 Allow to change remote media download timeout
1213

1314
2.7.2 (2015-09-23)
1415
- #135 Invalid HTTP request headers in non-cURL mode

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
2626
Summary
2727
-------
2828

29-
Use Codebird to connect to the Twitter REST **and Streaming API :sparkles:** from your PHP code.
29+
Use Codebird to connect to the Twitter REST **and Streaming API :sparkles:** from your PHP code.
3030
Codebird supports full 3-way OAuth as well as application-only auth.
3131

3232

@@ -240,6 +240,13 @@ $reply = $cb->media_upload(array(
240240

241241
:warning: *URLs containing Unicode characters should be normalised. A sample normalisation function can be found at http://stackoverflow.com/a/6059053/1816603*
242242

243+
To circumvent download issues when remote servers are slow to respond,
244+
you may customise the remote download timeout, like this:
245+
246+
```php
247+
$cb->setRemoteDownloadTimeout(10000); // milliseconds
248+
```
249+
243250
#### Video files
244251

245252
Uploading videos to Twitter (≤ 15MB, MP4) requires you to send them in chunks.

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