Skip to content

Commit 1e12f85

Browse files
authored
Merge pull request #65 from demyashev/feature/transpost-curl-timeout
[+] CurlTransport timeout
2 parents 3718d29 + ca3f885 commit 1e12f85

4 files changed

Lines changed: 20 additions & 6 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "PHP errors Catcher module for Hawk.so",
44
"keywords": ["hawk", "php", "error", "catcher"],
55
"type": "library",
6-
"version": "2.2.5",
6+
"version": "2.2.6",
77
"license": "MIT",
88
"require": {
99
"ext-curl": "*",

src/Catcher.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private function __construct(array $options)
157157
$builder->registerAddon(new Headers());
158158
$builder->registerAddon(new Environment());
159159

160-
$transport = new CurlTransport($options->getUrl());
160+
$transport = new CurlTransport($options->getUrl(), $options->getTimeout());
161161

162162
$this->handler = new Handler($options, $transport, $builder);
163163

src/Options.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class Options
2121
'url' => 'https://k1.hawk.so/',
2222
'release' => '',
2323
'error_types' => \E_ALL,
24-
'beforeSend' => null
24+
'beforeSend' => null,
25+
'timeout' => 10,
2526
];
2627

2728
/**
@@ -54,6 +55,11 @@ public function getUrl(): string
5455
return $this->options['url'];
5556
}
5657

58+
public function getTimeout(): int
59+
{
60+
return $this->options['timeout'];
61+
}
62+
5763
/**
5864
* Returns application release
5965
*

src/Transport/CurlTransport.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,22 @@ class CurlTransport implements TransportInterface
2020
*/
2121
private $url;
2222

23+
/**
24+
* CURLOPT_TIMEOUT
25+
*
26+
* @var int
27+
*/
28+
private $timeout;
29+
2330
/**
2431
* CurlTransport constructor.
2532
*
2633
* @param string $url
2734
*/
28-
public function __construct(string $url)
35+
public function __construct(string $url, int $timeout)
2936
{
3037
$this->url = $url;
38+
$this->timeout = $timeout;
3139
}
3240

3341
/**
@@ -52,11 +60,11 @@ public function send(Event $event)
5260

5361
$curl = curl_init();
5462
curl_setopt($curl, CURLOPT_URL, $this->url);
55-
curl_setopt($curl, CURLOPT_POST, 1);
63+
curl_setopt($curl, CURLOPT_POST, true);
5664
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($event, JSON_UNESCAPED_UNICODE));
5765
curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
5866
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
59-
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
67+
curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
6068
$response = curl_exec($curl);
6169
curl_close($curl);
6270

0 commit comments

Comments
 (0)