Skip to content

Commit

Permalink
Merge pull request #65 from demyashev/feature/transpost-curl-timeout
Browse files Browse the repository at this point in the history
[+] CurlTransport timeout
  • Loading branch information
neSpecc authored Dec 3, 2024
2 parents 3718d29 + ca3f885 commit 1e12f85
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
2 changes: 1 addition & 1 deletion src/Catcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
8 changes: 7 additions & 1 deletion src/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class Options
'url' => 'https://k1.hawk.so/',
'release' => '',
'error_types' => \E_ALL,
'beforeSend' => null
'beforeSend' => null,
'timeout' => 10,
];

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

public function getTimeout(): int
{
return $this->options['timeout'];
}

/**
* Returns application release
*
Expand Down
14 changes: 11 additions & 3 deletions src/Transport/CurlTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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);

Expand Down

0 comments on commit 1e12f85

Please sign in to comment.