Skip to content

Commit 9c00119

Browse files
committed
Improve accuracy of timeout call by using microtime()
1 parent 76ae124 commit 9c00119

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

tests/PHPCurlClass/server.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,17 +274,19 @@
274274
$server->serve($unsafe_file_path);
275275
exit;
276276
} elseif ($test === 'timeout') {
277+
// Use --no-buffer to view loading indicator (e.g.
278+
// curl --header "X-DEBUG-TEST: timeout" --include --no-buffer 127.0.0.1:8000/?seconds=3).
277279
header('Content-Type: application/json');
278-
$unsafe_seconds = $_GET['seconds'];
279-
$start = time();
280+
$unsafe_seconds = (int)$_GET['seconds'];
281+
$start = microtime(true);
280282
echo '{' . "\n";
281283
echo ' "loading": "';
282284
while (true) {
283285
echo '.';
284286
ob_flush();
285287
flush();
286288
sleep(1);
287-
$elapsed = time() - $start;
289+
$elapsed = microtime(true) - $start;
288290
if ($elapsed >= $unsafe_seconds) {
289291
break;
290292
}

0 commit comments

Comments
 (0)