Skip to content

Commit df29291

Browse files
Set timeout and proxy options on curl client
1 parent 47cd48f commit df29291

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/class-tiny-compress-client.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030

3131
class Tiny_Compress_Client extends Tiny_Compress {
3232

33+
/**
34+
* API request timeout in seconds.
35+
*
36+
* @since 3.6.8
37+
* @var int
38+
*/
39+
const API_TIMEOUT = 10;
40+
3341
private $last_error_code = 0;
3442
private $last_message = '';
3543
private $proxy;
@@ -176,6 +184,10 @@ private function set_request_options( $client ) {
176184
$property->setAccessible( true );
177185
$options = $property->getValue( $client );
178186

187+
// Set API request timeout to prevent indefinite hanging
188+
$options[ CURLOPT_TIMEOUT ] = self::API_TIMEOUT;
189+
$options[ CURLOPT_CONNECTTIMEOUT ] = self::API_TIMEOUT;
190+
179191
if ( TINY_DEBUG ) {
180192
$file = fopen( dirname( __FILE__ ) . '/curl.log', 'w' );
181193
if ( is_resource( $file ) ) {
@@ -194,5 +206,7 @@ private function set_request_options( $client ) {
194206
$options[ CURLOPT_PROXYUSERPWD ] = $this->proxy->authentication();
195207
}
196208
}
209+
210+
$property->setValue( $client, $options );
197211
}
198212
}

0 commit comments

Comments
 (0)