开发者

how does the php output buffer work (problem using $_SERVER['REQUEST_TIME'] to calculate script execution time)

开发者 https://www.devze.com 2023-03-18 22:12 出处:网络
i really didnt know how to word the title so i did the best i could. we have an issue where we calculate final script (web based) execution time.

i really didnt know how to word the title so i did the best i could.

we have an issue where we calculate final script (web based) execution time.

we do a simple

if(time()-$_SERVER['REQUEST_TIME']>X){
    logMe();
}

we find that sometimes the script is shown to take longer then X seconds to execute.

we are 100% sure this is not an issue with mysql, memcached, sphinx or any of the other usual culprits. please... just assume that its not 'something on our end' holding it up.

we even added this simple exec time check way way up in the script, before any heavy processing is done and there are still some hits. mainly far far away overseas clients.

so i am thinking this must be related to the output buffer somehow.

so the question is as follows:

in php + apache, how does the output buffer work? lets say you have the following:

[ 10KB HTML Body Head ]

[ Mysql query #1 ]

[ 50KB HTML Body ]

[ Mysql query #2 ]

[ 20KB HTML Body Footer ]

in this example, imagine you have a client connection that maxes out at 2KB/s.

so in the most ideal situation, it would take him 5 seconds to recieve the "HTML Body Head".

does that mean it will take 5 seconds before "Mysql query #1" is executed?

i think you get the idea. does a slow client connection affect how long it takes开发者_如何学Go for a script to be processed.

further more: do any php.ini settings affect this, and does flush()/ob_flush()?

thanks.


PHP will execute at maximum possible speed, and if output has to be buffered, the script will NOT pause until the buffer empties. It'll just keep filling up the buffer until the script ends.

How big is your 'X' value? $_SERVER['REQUEST_TIME'] comes from Apache itself, and is when the hit came in. There may be a pause in Apache to wait for a child process to become available to service the request. There can be pauses in PHP while waiting for a resource to open up (e.g. no more free database handles, so wait for one to free up). Then there can be delays for the database itself to execute and retrieve data off disk, etc...


PHP is serverside so the script execution time doesn't depend on the clients connection.

PHP usually ouputs once the script(s) has finished.

Flush can be used for long running script to output while this script hasn't finished yet.

Still the client have to download the page.

Don´t think there is a lot you can do when you have clients with 2KB/s other than upgrading their connection :P

0

精彩评论

暂无评论...
验证码 换一张
取 消