start() takes VERY LONG TIME
Mys site works very slowly (and I didn't have any idea about why). It is based on Zend Application, I used to make about tens of such sites, so I'm sure that MY code is OK.
I installed xdebugger on server, tried to profile it and guess what? php::session_start() took 48.675 seconds. Fourty Eight and a Half Seconds! It's unbelievable! What could be the reason of this? It's common operation, why could it execute SO long? How to fix such behaviour, which configs to edit? Searched over Google, but found no good answer (almost everywhere there's a question, but no answer). Thanks in before!
My guess would be the garbage collection routine, which gets run inside of the native session_start()
function. Maybe you've done something that keeps many old session files around, like changed the max life time? Or maybe you've decided it would be a good idea to store them in a database, but forgot to create a suitable index? The native GC routine stat()'s every single session file to check for expiration. This is time consuming if there's a lot of files built up.
edit : to help you for debugging only , disable garbage collection by temporarily setting session.gc-probability:
session.gc-probability = 0
Make sure the settings stick, I don't know what the zend framework might be doing here.
PS It's difficult to suggestion a fix without knowing the cause. My answer is meant to guide you towards identifying the cause.
session_start
(with sessions stored in files) is blocking in PHP, so this issue will appear if you try to start several server sessions for the same browser session (AJAX or multiple browser tabs/windows). Each session_start
will wait until the other sessions have been closed.
See here: http://konrness.com/php5/how-to-prevent-blocking-php-requests/
Try changing from files to database storage of sessions.
I have had this problem and am surprised that nobody has posted this specific response. It may not be it but it is worth checking.
PHP LOCKS THE SESSION FILE while a page is processing, so that page can have exclusive access to it. Think about it, the sess_184c9aciqoc file is not a database, so two calls in the same session can't access it simultaneously. So if you have a lot of ajax calls, you can get a "traffic jam". Once you start doing advanced scripting this is a gotcha to beware of. by the way, here is a function to store an array of timestamps. I used this to figure out session start was the culprit:
//time function for benchmarking
if( function_exists('gmicrotime')){
function gmicrotime($n=''){
#version 1.1, 2007-05-09
//store array of all calls
global $mT;
list($usec, $sec) = explode(' ',microtime());
if(!isset($mT['_base_']))$mT['_base_']=$sec;
$t=round((float)$usec + (float)(substr($sec,-4)),6);
$mT['all'][]=$t;
if($n){
if(isset($mT['indexed'][$n])){
//store repeated calls with same index. If in a loop, add a $i if needed
if(is_array($mT['indexed'][$n])){
$mT['indexed'][$n][]=$t;
}else{
$mT['indexed'][$n]=array($mT['indexed'][$n],$t);
}
}else $mT['indexed'][$n]=$t;
}
//return elapsed since last call (in the local array)
$u=$mT['all'];
if(count($u)>1){
$mT['_total_']=$u[count($u)-1] - $u[0];
return round(1000*($u[count($u)-1]-$u[count($u)-2]),6);
}
}
gmicrotime('pageStart');
}
then i call as follows:
gmicrotime('beforeSessionStart');
session_start();
gmicrotime('afterSessionStart');
do_something_slow();
gmicrotime('afterSlowProcess');
//etc..
echo '<pre>';
print_r($mT);
Hope this is helpful!
链接地址: http://www.djcxy.com/p/85448.html上一篇: 我如何找出编译器花费的时间?
下一篇: start()需要很长时间