Skip to content

Commit

Permalink
Merge f738da8 into 6d3a6e8
Browse files Browse the repository at this point in the history
  • Loading branch information
matus-tomlein committed Dec 20, 2022
2 parents 6d3a6e8 + f738da8 commit 694dae7
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/Emitters/CurlEmitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,24 @@ class CurlEmitter extends Emitter {
private $curl_buffer = array();
private $curl_limit;
private $rolling_window;
private $curl_timeout;

/**
* Constructs an async curl emitter.
*
* @param string $uri
* @param string|null $protocol
* @param string|null $type
* @param int|null $buffer_size
* @param bool $debug
* @param string $uri - Collector URI
* @param string|null $protocol - What protocol we are using for the collector
* @param string|null $type - The type of request we will be making to the collector
* @param int|null $buffer_size - Emitter buffer size
* @param bool $debug - Debug mode
* @param int|null $curl_timeout - Maximum time the request is allowed to take, in seconds
*/
public function __construct($uri, $protocol = NULL, $type = NULL, $buffer_size = NULL, $debug = false) {
public function __construct($uri, $protocol = NULL, $type = NULL, $buffer_size = NULL, $debug = false, $curl_timeout = NULL) {
$this->type = $this->getRequestType($type);
$this->url = $this->getCollectorUrl($this->type, $uri, $protocol);
$this->curl_limit = $this->type == "POST" ? self::CURL_AMOUNT_POST : self::CURL_AMOUNT_GET;
$this->rolling_window = $this->type == "POST" ? self::CURL_WINDOW_POST : self::CURL_WINDOW_GET;
$this->curl_timeout = $curl_timeout;

// If debug is on create a requests_results array
if ($debug === true) {
Expand Down Expand Up @@ -229,6 +232,9 @@ private function getCurlRequest($payload, $type) {
curl_setopt($ch, CURLOPT_URL, $this->url."?".$payload);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($this->curl_timeout != NULL) {
curl_setopt($ch, CURLOPT_TIMEOUT, $this->curl_timeout);
}
return $ch;
}

Expand Down

0 comments on commit 694dae7

Please sign in to comment.