Skip to content

Commit

Permalink
Merge pull request #173 from zoonru/float_timeout
Browse files Browse the repository at this point in the history
Support floats in timeout and connect_timeout
  • Loading branch information
isublimity committed Aug 9, 2022
2 parents 588d374 + 7ad35c0 commit 3c01fa0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
10 changes: 5 additions & 5 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,25 +189,25 @@ public function setTimeout(int $timeout)
}

/**
* @return mixed
* @return float
*/
public function getTimeout()
public function getTimeout(): float
{
return $this->settings()->getTimeOut();
}

/**
* ConnectTimeOut in seconds ( support 1.5 = 1500ms )
*/
public function setConnectTimeOut(int $connectTimeOut)
public function setConnectTimeOut(float $connectTimeOut)
{
$this->transport()->setConnectTimeOut($connectTimeOut);
}

/**
* @return int
* @return float
*/
public function getConnectTimeOut()
public function getConnectTimeOut(): float
{
return $this->transport()->getConnectTimeOut();
}
Expand Down
12 changes: 6 additions & 6 deletions src/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(Http $client)
$default = [
'extremes' => false,
'readonly' => true,
'max_execution_time' => 20,
'max_execution_time' => 20.0,
'enable_http_compression' => 1,
'https' => false,
];
Expand Down Expand Up @@ -93,9 +93,9 @@ public function database($db)
}

/**
* @return mixed
* @return float
*/
public function getTimeOut()
public function getTimeOut(): float
{
return $this->get('max_execution_time');
}
Expand Down Expand Up @@ -172,12 +172,12 @@ public function makeSessionId()
}

/**
* @param int $time
* @param float $time
* @return $this
*/
public function max_execution_time($time)
public function max_execution_time(float $time)
{
$this->set('max_execution_time', intval($time));
$this->set('max_execution_time',$time);
return $this;
}

Expand Down
12 changes: 6 additions & 6 deletions src/Transport/CurlerRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -488,12 +488,12 @@ public function parameters($data)
/**
* The number of seconds to wait when trying to connect. Use 0 for infinite waiting.
*
* @param int $seconds
* @param float $seconds
* @return $this
*/
public function connectTimeOut($seconds = 1)
public function connectTimeOut(float $seconds = 1.0)
{
$this->options[CURLOPT_CONNECTTIMEOUT] = $seconds;
$this->options[CURLOPT_CONNECTTIMEOUT_MS] = (int) ($seconds*1000.0);
return $this;
}

Expand All @@ -503,9 +503,9 @@ public function connectTimeOut($seconds = 1)
* @param float $seconds
* @return $this
*/
public function timeOut($seconds = 10)
public function timeOut(float $seconds = 10)
{
return $this->timeOutMs(intval($seconds * 1000));
return $this->timeOutMs((int) ($seconds * 1000.0));
}

/**
Expand All @@ -514,7 +514,7 @@ public function timeOut($seconds = 10)
* @param int $ms millisecond
* @return $this
*/
protected function timeOutMs($ms = 10000)
protected function timeOutMs(int $ms = 10000)
{
$this->options[CURLOPT_TIMEOUT_MS] = $ms;
return $this;
Expand Down
10 changes: 5 additions & 5 deletions src/Transport/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ class Http
/**
* Count seconds (int)
*
* @var int
* @var float
*/
private $_connectTimeOut = 5;
private $_connectTimeOut = 5.0;

/**
* @var callable
Expand Down Expand Up @@ -413,9 +413,9 @@ public function getCountPendingQueue(): int
/**
* set Connect TimeOut in seconds [CURLOPT_CONNECTTIMEOUT] ( int )
*
* @param int $connectTimeOut
* @param float $connectTimeOut
*/
public function setConnectTimeOut(int $connectTimeOut)
public function setConnectTimeOut(float $connectTimeOut)
{
$this->_connectTimeOut = $connectTimeOut;
}
Expand All @@ -425,7 +425,7 @@ public function setConnectTimeOut(int $connectTimeOut)
*
* @return int
*/
public function getConnectTimeOut(): int
public function getConnectTimeOut(): float
{
return $this->_connectTimeOut;
}
Expand Down

0 comments on commit 3c01fa0

Please sign in to comment.