Skip to content

Commit ec734f9

Browse files
committed
New parameter to control connection timeout
1 parent 6185c4b commit ec734f9

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/MailQ/Connector.php

+25-3
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,38 @@ class Connector
1313

1414
private $baseUrl;
1515

16+
private $timeout = 0;
17+
18+
private $connectionTimeout = 300;
19+
1620
private static $instance;
1721

18-
function __construct($baseUrl, $apiKey)
22+
/**
23+
* Connector constructor.
24+
* @param $baseUrl
25+
* @param $apiKey
26+
* @param int $connectionTimeout
27+
* @param int $timeout
28+
*/
29+
public function __construct($baseUrl, $apiKey, $connectionTimeout = 300, $timeout = 0)
1930
{
2031
$this->baseUrl = $baseUrl;
2132
$this->apiKey = $apiKey;
33+
$this->connectionTimeout = $connectionTimeout;
34+
$this->timeout = $timeout;
2235
}
2336

24-
public static function getInstance($baseUrl, $apiKey)
37+
/**
38+
* @param $baseUrl
39+
* @param $apiKey
40+
* @param int $connectionTimeout
41+
* @param int $timeout
42+
* @return Connector
43+
*/
44+
public static function getInstance($baseUrl, $apiKey, $connectionTimeout = 300, $timeout = 0)
2545
{
2646
if (!isset(self::$instance)) {
27-
self::$instance = new Connector($baseUrl, $apiKey);
47+
self::$instance = new Connector($baseUrl, $apiKey,$connectionTimeout,$timeout);
2848
}
2949
return self::$instance;
3050
}
@@ -55,6 +75,8 @@ public function sendRequest(Request $request)
5575
curl_setopt($ch, CURLOPT_HTTPHEADER, $curlHeaders);
5676
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
5777
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
78+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT ,$this->connectionTimeout);
79+
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
5880
if ($request->hasContent()) {
5981
curl_setopt($ch, CURLOPT_POSTFIELDS, $request->getContent());
6082
}

0 commit comments

Comments
 (0)