javascript - Inconsistent loading time for JS and PHP -


i have php script being loaded js through jquery's $.ajax. measured execution time of php script using:

$start = microtime(); // top part of code // other processes includes aes decryption $end = microtime(); // bottom part of code file_put_contents('log.txt','time took: '.($end-$start)."\n",file_append); 

it measured somewhere less 1 second. there no prepend/append php scripts.

in js $.ajax code, have measured execution time by:

success: function(response) {     console.log(date('g:i:s a') + ' time received\n');     // other processes including aes decryption     console.log(date('g:i:s a') + ' time processed\n'); } 

the time same time received , time processed.

however, when check chrome developer tools, it claims php script loaded 8 seconds.

what wrong in how measured these things? i'm php loading fast how come chrome reports took more 8 seconds?

i'm using localhost , web server fast , time encountered problem. other ajax calls fast.

in php section, make sure you're using microtime(true) you're working floating point numbers instead of strings. using subtraction on strings may yield incorrect results.


example: http://ideone.com/fwkjf2

<?php  // wrong $start = microtime(); sleep(3); $stop  = microtime(); echo ($stop - $start) . php_eol;  // prints 8.000000000008e-5  // correct $start = microtime(true); sleep(3); $stop  = microtime(true); echo ($stop - $start) . php_eol;  // prints 3.0000791549683  ?> 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -