Skip to content

Commit

Permalink
Fix marcushat#41 - New feature allowing user to set the CURLOPT_CONNE…
Browse files Browse the repository at this point in the history
…CTTIMEOUT(_MS) option
  • Loading branch information
Ljz7 committed Mar 5, 2019
1 parent 1f3fc01 commit 5de825f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Rolling Curl X is a fork of Rolling Curl wrapper cURL Multi. It aims at making c
MIT

#### Version
3.0.0
3.0.3

#### Requirements
PHP 5.4+
Expand Down Expand Up @@ -48,6 +48,9 @@ There's more if you need it though...
//Set a timeout on all requests:
$RCX->setTimeout(3000); //in milliseconds

//Set a connection timeout on all requests:
$RCX->setConnectTimeout(3000); //in milliseconds

//To set options for all requests(will be overridden by individual request options):
$RCX->setOptions([$curl_options]);

Expand Down
15 changes: 11 additions & 4 deletions src/rollingcurlx.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
---------- RollingCurlX 3.0.2 -----------
---------- RollingCurlX 3.0.3 -----------
an easy to use curl_multi wrapper for php
Copyright (c) 2015-2017 Marcus Leath
Expand All @@ -16,6 +16,7 @@
private $_headers = []; //shared cURL request headers
private $_callback = NULL; //default callback
private $_timeout = 5000; //all requests must be completed by this time
private $_connect_timeout = 5000; //all connections must be completed by this time
public $requests = []; //request_queue


Expand Down Expand Up @@ -51,6 +52,12 @@ public function setTimeout($timeout) { //in milliseconds
}
}

public function setConnectTimeout($connect_timeout) { //in milliseconds
if($connect_timeout > 0) {
$this->_connect_timeout = $connect_timeout;
}
}

//Add a request to the request queue
public function addRequest(
$url,
Expand Down Expand Up @@ -151,12 +158,12 @@ private function buildOptions(array $request) {
$options[CURLOPT_NOSIGNAL] = 1;

if(version_compare($this->_curl_version, '7.16.2') >= 0) {
$options[CURLOPT_CONNECTTIMEOUT_MS] = $this->_timeout;
$options[CURLOPT_CONNECTTIMEOUT_MS] = $this->_connect_timeout;
$options[CURLOPT_TIMEOUT_MS] = $this->_timeout;
unset($options[CURLOPT_CONNECTTIMEOUT]);
unset($options[CURLOPT_TIMEOUT]);
} else {
$options[CURLOPT_CONNECTTIMEOUT] = round($this->_timeout / 1000);
$options[CURLOPT_CONNECTTIMEOUT] = round($this->_connect_timeout / 1000);
$options[CURLOPT_TIMEOUT] = round($this->_timeout / 1000);
unset($options[CURLOPT_CONNECTTIMEOUT_MS]);
unset($options[CURLOPT_TIMEOUT_MS]);
Expand Down Expand Up @@ -269,4 +276,4 @@ private function stopTimer(array &$request) {
private $curle_msgs = [CURLE_OK => 'OK', CURLE_UNSUPPORTED_PROTOCOL => 'UNSUPPORTED_PROTOCOL', CURLE_FAILED_INIT => 'FAILED_INIT', CURLE_URL_MALFORMAT => 'URL_MALFORMAT', CURLE_URL_MALFORMAT_USER => 'URL_MALFORMAT_USER', CURLE_COULDNT_RESOLVE_PROXY => 'COULDNT_RESOLVE_PROXY', CURLE_COULDNT_RESOLVE_HOST => 'COULDNT_RESOLVE_HOST', CURLE_COULDNT_CONNECT => 'COULDNT_CONNECT', CURLE_FTP_WEIRD_SERVER_REPLY => 'FTP_WEIRD_SERVER_REPLY', CURLE_FTP_ACCESS_DENIED => 'FTP_ACCESS_DENIED', CURLE_FTP_USER_PASSWORD_INCORRECT => 'FTP_USER_PASSWORD_INCORRECT', CURLE_FTP_WEIRD_PASS_REPLY => 'FTP_WEIRD_PASS_REPLY', CURLE_FTP_WEIRD_USER_REPLY => 'FTP_WEIRD_USER_REPLY', CURLE_FTP_WEIRD_PASV_REPLY => 'FTP_WEIRD_PASV_REPLY', CURLE_FTP_WEIRD_227_FORMAT => 'FTP_WEIRD_227_FORMAT', CURLE_FTP_CANT_GET_HOST => 'FTP_CANT_GET_HOST', CURLE_FTP_CANT_RECONNECT => 'FTP_CANT_RECONNECT', CURLE_FTP_COULDNT_SET_BINARY => 'FTP_COULDNT_SET_BINARY', CURLE_PARTIAL_FILE => 'PARTIAL_FILE', CURLE_FTP_COULDNT_RETR_FILE => 'FTP_COULDNT_RETR_FILE', CURLE_FTP_WRITE_ERROR => 'FTP_WRITE_ERROR', CURLE_FTP_QUOTE_ERROR => 'FTP_QUOTE_ERROR', CURLE_HTTP_NOT_FOUND => 'HTTP_NOT_FOUND', CURLE_WRITE_ERROR => 'WRITE_ERROR', CURLE_MALFORMAT_USER => 'MALFORMAT_USER', CURLE_FTP_COULDNT_STOR_FILE => 'FTP_COULDNT_STOR_FILE', CURLE_READ_ERROR => 'READ_ERROR', CURLE_OUT_OF_MEMORY => 'OUT_OF_MEMORY', CURLE_OPERATION_TIMEOUTED => 'OPERATION_TIMEOUTED', CURLE_FTP_COULDNT_SET_ASCII => 'FTP_COULDNT_SET_ASCII', CURLE_FTP_PORT_FAILED => 'FTP_PORT_FAILED', CURLE_FTP_COULDNT_USE_REST => 'FTP_COULDNT_USE_REST', CURLE_FTP_COULDNT_GET_SIZE => 'FTP_COULDNT_GET_SIZE', CURLE_HTTP_RANGE_ERROR => 'HTTP_RANGE_ERROR', CURLE_HTTP_POST_ERROR => 'HTTP_POST_ERROR', CURLE_SSL_CONNECT_ERROR => 'SSL_CONNECT_ERROR', CURLE_FTP_BAD_DOWNLOAD_RESUME => 'FTP_BAD_DOWNLOAD_RESUME', CURLE_FILE_COULDNT_READ_FILE => 'FILE_COULDNT_READ_FILE', CURLE_LDAP_CANNOT_BIND => 'LDAP_CANNOT_BIND', CURLE_LDAP_SEARCH_FAILED => 'LDAP_SEARCH_FAILED', CURLE_LIBRARY_NOT_FOUND => 'LIBRARY_NOT_FOUND', CURLE_FUNCTION_NOT_FOUND => 'FUNCTION_NOT_FOUND', CURLE_ABORTED_BY_CALLBACK => 'ABORTED_BY_CALLBACK', CURLE_BAD_FUNCTION_ARGUMENT => 'BAD_FUNCTION_ARGUMENT', CURLE_BAD_CALLING_ORDER => 'BAD_CALLING_ORDER', CURLE_HTTP_PORT_FAILED => 'HTTP_PORT_FAILED', CURLE_BAD_PASSWORD_ENTERED => 'BAD_PASSWORD_ENTERED', CURLE_TOO_MANY_REDIRECTS => 'TOO_MANY_REDIRECTS', CURLE_UNKNOWN_TELNET_OPTION => 'UNKNOWN_TELNET_OPTION', CURLE_TELNET_OPTION_SYNTAX => 'TELNET_OPTION_SYNTAX', CURLE_OBSOLETE => 'OBSOLETE', CURLE_SSL_PEER_CERTIFICATE => 'SSL_PEER_CERTIFICATE', CURLE_GOT_NOTHING => 'GOT_NOTHING', CURLE_SSL_ENGINE_NOTFOUND => 'SSL_ENGINE_NOTFOUND', CURLE_SSL_ENGINE_SETFAILED => 'SSL_ENGINE_SETFAILED', CURLE_SEND_ERROR => 'SEND_ERROR', CURLE_RECV_ERROR => 'RECV_ERROR', CURLE_SHARE_IN_USE => 'SHARE_IN_USE', CURLE_SSL_CERTPROBLEM => 'SSL_CERTPROBLEM', CURLE_SSL_CIPHER => 'SSL_CIPHER', CURLE_SSL_CACERT => 'SSL_CACERT', CURLE_BAD_CONTENT_ENCODING => 'BAD_CONTENT_ENCODING', CURLE_LDAP_INVALID_URL => 'LDAP_INVALID_URL', CURLE_FILESIZE_EXCEEDED => 'FILESIZE_EXCEEDED', CURLE_FTP_SSL_FAILED => 'FTP_SSL_FAILED', CURLE_SSH => 'SSH'
];
}
?>
?>

0 comments on commit 5de825f

Please sign in to comment.