Skip to content

Commit 6a729c6

Browse files
author
Matej Humpal
committed
Ability to set timeouts for CurlHttpAdapter
1 parent 63f4b7b commit 6a729c6

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/Geocoder/HttpAdapter/CurlHttpAdapter.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@
1717
*/
1818
class CurlHttpAdapter implements HttpAdapterInterface
1919
{
20+
private $timeout;
21+
22+
private $connectTimeout;
23+
24+
public function __construct($timeout = null, $connectTimeout = null)
25+
{
26+
$this->timeout = $timeout;
27+
$this->connectTimeout = $connectTimeout;
28+
}
29+
2030
/**
2131
* {@inheritDoc}
2232
*/
@@ -29,6 +39,15 @@ public function getContent($url)
2939
$c = curl_init();
3040
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
3141
curl_setopt($c, CURLOPT_URL, $url);
42+
43+
if ($this->timeout) {
44+
curl_setopt($c, CURLOPT_TIMEOUT, $this->timeout);
45+
}
46+
47+
if ($this->connectTimeout) {
48+
curl_setopt($c, CURLOPT_CONNECTTIMEOUT, $this->connectTimeout);
49+
}
50+
3251
$content = curl_exec($c);
3352
curl_close($c);
3453

0 commit comments

Comments
 (0)