Skip to content

Commit 3c01fa0

Browse files
authored
Merge pull request smi2#173 from zoonru/float_timeout
Support floats in timeout and connect_timeout
2 parents 588d374 + 7ad35c0 commit 3c01fa0

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

src/Client.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,25 +189,25 @@ public function setTimeout(int $timeout)
189189
}
190190

191191
/**
192-
* @return mixed
192+
* @return float
193193
*/
194-
public function getTimeout()
194+
public function getTimeout(): float
195195
{
196196
return $this->settings()->getTimeOut();
197197
}
198198

199199
/**
200200
* ConnectTimeOut in seconds ( support 1.5 = 1500ms )
201201
*/
202-
public function setConnectTimeOut(int $connectTimeOut)
202+
public function setConnectTimeOut(float $connectTimeOut)
203203
{
204204
$this->transport()->setConnectTimeOut($connectTimeOut);
205205
}
206206

207207
/**
208-
* @return int
208+
* @return float
209209
*/
210-
public function getConnectTimeOut()
210+
public function getConnectTimeOut(): float
211211
{
212212
return $this->transport()->getConnectTimeOut();
213213
}

src/Settings.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct(Http $client)
3232
$default = [
3333
'extremes' => false,
3434
'readonly' => true,
35-
'max_execution_time' => 20,
35+
'max_execution_time' => 20.0,
3636
'enable_http_compression' => 1,
3737
'https' => false,
3838
];
@@ -93,9 +93,9 @@ public function database($db)
9393
}
9494

9595
/**
96-
* @return mixed
96+
* @return float
9797
*/
98-
public function getTimeOut()
98+
public function getTimeOut(): float
9999
{
100100
return $this->get('max_execution_time');
101101
}
@@ -172,12 +172,12 @@ public function makeSessionId()
172172
}
173173

174174
/**
175-
* @param int $time
175+
* @param float $time
176176
* @return $this
177177
*/
178-
public function max_execution_time($time)
178+
public function max_execution_time(float $time)
179179
{
180-
$this->set('max_execution_time', intval($time));
180+
$this->set('max_execution_time',$time);
181181
return $this;
182182
}
183183

src/Transport/CurlerRequest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -488,12 +488,12 @@ public function parameters($data)
488488
/**
489489
* The number of seconds to wait when trying to connect. Use 0 for infinite waiting.
490490
*
491-
* @param int $seconds
491+
* @param float $seconds
492492
* @return $this
493493
*/
494-
public function connectTimeOut($seconds = 1)
494+
public function connectTimeOut(float $seconds = 1.0)
495495
{
496-
$this->options[CURLOPT_CONNECTTIMEOUT] = $seconds;
496+
$this->options[CURLOPT_CONNECTTIMEOUT_MS] = (int) ($seconds*1000.0);
497497
return $this;
498498
}
499499

@@ -503,9 +503,9 @@ public function connectTimeOut($seconds = 1)
503503
* @param float $seconds
504504
* @return $this
505505
*/
506-
public function timeOut($seconds = 10)
506+
public function timeOut(float $seconds = 10)
507507
{
508-
return $this->timeOutMs(intval($seconds * 1000));
508+
return $this->timeOutMs((int) ($seconds * 1000.0));
509509
}
510510

511511
/**
@@ -514,7 +514,7 @@ public function timeOut($seconds = 10)
514514
* @param int $ms millisecond
515515
* @return $this
516516
*/
517-
protected function timeOutMs($ms = 10000)
517+
protected function timeOutMs(int $ms = 10000)
518518
{
519519
$this->options[CURLOPT_TIMEOUT_MS] = $ms;
520520
return $this;

src/Transport/Http.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ class Http
7777
/**
7878
* Count seconds (int)
7979
*
80-
* @var int
80+
* @var float
8181
*/
82-
private $_connectTimeOut = 5;
82+
private $_connectTimeOut = 5.0;
8383

8484
/**
8585
* @var callable
@@ -413,9 +413,9 @@ public function getCountPendingQueue(): int
413413
/**
414414
* set Connect TimeOut in seconds [CURLOPT_CONNECTTIMEOUT] ( int )
415415
*
416-
* @param int $connectTimeOut
416+
* @param float $connectTimeOut
417417
*/
418-
public function setConnectTimeOut(int $connectTimeOut)
418+
public function setConnectTimeOut(float $connectTimeOut)
419419
{
420420
$this->_connectTimeOut = $connectTimeOut;
421421
}
@@ -425,7 +425,7 @@ public function setConnectTimeOut(int $connectTimeOut)
425425
*
426426
* @return int
427427
*/
428-
public function getConnectTimeOut(): int
428+
public function getConnectTimeOut(): float
429429
{
430430
return $this->_connectTimeOut;
431431
}

0 commit comments

Comments
 (0)