diff --git a/composer.json b/composer.json index ea4053f..f5236d0 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "PHP errors Catcher module for Hawk.so", "keywords": ["hawk", "php", "error", "catcher"], "type": "library", - "version": "2.2.5", + "version": "2.2.6", "license": "MIT", "require": { "ext-curl": "*", diff --git a/src/Catcher.php b/src/Catcher.php index 6403630..17f84c1 100644 --- a/src/Catcher.php +++ b/src/Catcher.php @@ -157,7 +157,7 @@ private function __construct(array $options) $builder->registerAddon(new Headers()); $builder->registerAddon(new Environment()); - $transport = new CurlTransport($options->getUrl()); + $transport = new CurlTransport($options->getUrl(), $options->getTimeout()); $this->handler = new Handler($options, $transport, $builder); diff --git a/src/Options.php b/src/Options.php index 3478f07..7a7d11c 100644 --- a/src/Options.php +++ b/src/Options.php @@ -21,7 +21,8 @@ class Options 'url' => 'https://k1.hawk.so/', 'release' => '', 'error_types' => \E_ALL, - 'beforeSend' => null + 'beforeSend' => null, + 'timeout' => 10, ]; /** @@ -54,6 +55,11 @@ public function getUrl(): string return $this->options['url']; } + public function getTimeout(): int + { + return $this->options['timeout']; + } + /** * Returns application release * diff --git a/src/Transport/CurlTransport.php b/src/Transport/CurlTransport.php index 797a6e4..1b55e5a 100644 --- a/src/Transport/CurlTransport.php +++ b/src/Transport/CurlTransport.php @@ -20,14 +20,22 @@ class CurlTransport implements TransportInterface */ private $url; + /** + * CURLOPT_TIMEOUT + * + * @var int + */ + private $timeout; + /** * CurlTransport constructor. * * @param string $url */ - public function __construct(string $url) + public function __construct(string $url, int $timeout) { $this->url = $url; + $this->timeout = $timeout; } /** @@ -52,11 +60,11 @@ public function send(Event $event) $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $this->url); - curl_setopt($curl, CURLOPT_POST, 1); + curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($event, JSON_UNESCAPED_UNICODE)); curl_setopt($curl, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_TIMEOUT, 10); + curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout); $response = curl_exec($curl); curl_close($curl);