Вопрос

I'm trying to profile my Kohana project using Profiler. I'm on XAMPP on Windows with php 5.5.3. On this version of PHP I'm getting 0.000000 sec. execution time for main request, find_file() or database calls. Same behavior with PHP 5.4.19.

If I move the project to XAMPP with PHP 5.3 everything works as expected - single database query takes something around 0.00012-0.00014 sec., etc. I suspect something has changed in microtime(true) function since 5.3 version. If I'm measuring rand(0, 9999) with 10000 iterations with the simple time calculation:

$time_start = microtime(true);
for($i=0; $i<10000; $i++) {
    rand(0, 9999);
}
$time_end = microtime(true);
$time = $time_end - $time_start;

I still getting the same times before and after function call, so execution time equals to 0, which is not possible of course.

Is there any way to fix this behavior on PHP 5.4 or 5.5 on Windows to get more precise timings? thanks!

Это было полезно?

Решение

Looking on the php source code

if(6 == EG(windows_version_info).dwMajorVersion && 2 >= EG(windows_version_info).dwMinorVersion) {
        GetSystemTimePreciseAsFileTime(&ft); /* highest possible resolution <1us */
    } else {
        GetSystemTimeAsFileTime(&ft);   /* 100ns blocks since 01-Jan-1641 */
    }

it seems like Windows 8 has more precise timing function so that's why it's not repeatable on that version.

I was able to fix this problem by using calibration tool from http://windowstimestamp.com.

Thanks everyone for the answers!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top