Improve accuracy of timeout call by using microtime()

This commit is contained in:
Zach Borboa
2020-05-12 22:41:02 -07:00
parent 76ae1241cb
commit 9c00119ab5
+5 -3
View File
@@ -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;
}