mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-09-19 14:56:31 +00:00
Improve accuracy of timeout call by using microtime()
This commit is contained in:
@@ -274,9 +274,11 @@ if ($test === 'http_basic_auth') {
|
||||
$server->serve($unsafe_file_path);
|
||||
exit;
|
||||
} elseif ($test === 'timeout') {
|
||||
// Use --no-buffer to view loading indicator (e.g.
|
||||
// curl --header "X-DEBUG-TEST: timeout" --include --no-buffer 127.0.0.1:8000/?seconds=3).
|
||||
header('Content-Type: application/json');
|
||||
$unsafe_seconds = $_GET['seconds'];
|
||||
$start = time();
|
||||
$unsafe_seconds = (int)$_GET['seconds'];
|
||||
$start = microtime(true);
|
||||
echo '{' . "\n";
|
||||
echo ' "loading": "';
|
||||
while (true) {
|
||||
@@ -284,7 +286,7 @@ if ($test === 'http_basic_auth') {
|
||||
ob_flush();
|
||||
flush();
|
||||
sleep(1);
|
||||
$elapsed = time() - $start;
|
||||
$elapsed = microtime(true) - $start;
|
||||
if ($elapsed >= $unsafe_seconds) {
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user