From 9c00119ab5e2638a8dbfcab60a38419d9fa94bc5 Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Tue, 12 May 2020 22:41:02 -0700 Subject: [PATCH] Improve accuracy of timeout call by using microtime() --- tests/PHPCurlClass/server.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/PHPCurlClass/server.php b/tests/PHPCurlClass/server.php index f3c9259..fc4ab7b 100644 --- a/tests/PHPCurlClass/server.php +++ b/tests/PHPCurlClass/server.php @@ -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; }