Skip to content

Commit

Permalink
HTTPClient: Replace time() method with direct microtime(true) call
Browse files Browse the repository at this point in the history
  • Loading branch information
glensc committed Apr 5, 2023
1 parent 88743d1 commit e8b8bf8
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions inc/HTTP/HTTPClient.php
Expand Up @@ -162,7 +162,7 @@ public function post($url,$data){
* @author Andreas Gohr <andi@splitbrain.org>
*/
public function sendRequest($url,$data='',$method='GET'){
$this->start = $this->time();
$this->start = microtime(true);
$this->error = '';
$this->status = 0;
$this->resp_body = '';
Expand Down Expand Up @@ -583,7 +583,7 @@ protected function sendData($socket, $data, $message) {
$written = 0;
while($written < $towrite){
// check timeout
$time_used = $this->time() - $this->start;
$time_used = microtime(true) - $this->start;
if($time_used > $this->timeout)
throw new HTTPClientException(sprintf('Timeout while sending %s (%.3fs)',$message, $time_used), -100);
if(feof($socket))
Expand Down Expand Up @@ -628,7 +628,7 @@ protected function readData($socket, $nbytes, $message, $ignore_eof = false) {
if ($nbytes < 0) $nbytes = 0;
$to_read = $nbytes;
do {
$time_used = $this->time() - $this->start;
$time_used = microtime(true) - $this->start;
if ($time_used > $this->timeout)
throw new HTTPClientException(
sprintf('Timeout while reading %s after %d bytes (%.3fs)', $message,
Expand Down Expand Up @@ -675,7 +675,7 @@ protected function readData($socket, $nbytes, $message, $ignore_eof = false) {
protected function readLine($socket, $message) {
$r_data = '';
do {
$time_used = $this->time() - $this->start;
$time_used = microtime(true) - $this->start;
if ($time_used > $this->timeout)
throw new HTTPClientException(
sprintf('Timeout while reading %s (%.3fs) >%s<', $message, $time_used, $r_data),
Expand Down Expand Up @@ -724,7 +724,7 @@ protected function debug($info,$var=null){
* @param mixed $var
*/
protected function debugHtml($info, $var=null){
print '<b>'.$info.'</b> '.($this->time() - $this->start).'s<br />';
print '<b>'.$info.'</b> '.(microtime(true) - $this->start).'s<br />';
if(!is_null($var)){
ob_start();
print_r($var);
Expand All @@ -741,20 +741,11 @@ protected function debugHtml($info, $var=null){
* @param mixed $var
*/
protected function debugText($info, $var=null){
print '*'.$info.'* '.($this->time() - $this->start)."s\n";
print '*'.$info.'* '.(microtime(true) - $this->start)."s\n";
if(!is_null($var)) print_r($var);
print "\n-----------------------------------------------\n";
}

/**
* Return current timestamp in microsecond resolution
*
* @return float
*/
protected static function time(){
return microtime(true);
}

/**
* convert given header string to Header array
*
Expand Down

0 comments on commit e8b8bf8

Please sign in to comment.