cancel
Showing results for 
Search instead for 
Did you mean: 

PHP start_session() running very slowly

Kiwi2
Grafter
Posts: 42
Thanks: 5
Fixes: 2
Registered: ‎01-11-2015

PHP start_session() running very slowly

Sometimes the pages in my CGI webspace load very slowly. I've tracked it down to calls to php's session_start() which, when it's slow, take a little over 30 seconds. It interesting that this time when slow is always just over 30 secs, as if something's timing out.
Can you think of a reason why session_start() would run slowly, or any ideas of things I could try?
Peter
4 REPLIES 4
spraxyt
Superuser
Superuser
Posts: 10,063
Thanks: 1,369
Fixes: 75
Registered: ‎06-04-2007

Re: PHP start_session() running very slowly

As you say taking just over 30 seconds when "slow" could be time-out related. Do you have a feeling for how long this might have been happening? Weeks?
I wonder if "slow" instances mean a change of server host, "not slow" instances the same host. Is it possible to reproduce the problem using a basic page that simply displays the hostname of the server that generated it?
David
David
Kiwi2
Grafter
Posts: 42
Thanks: 5
Fixes: 2
Registered: ‎01-11-2015

Re: PHP start_session() running very slowly

Interesting thoughts. I've had suspicions that this has been hapenning on and off for a few months now. I've put log writes in my PHP before and after the call, so I'm prety sure that's where the problem is. Sometimes when I refresh the page it takes just over 30 sec, sometimes less than a second (but nothing in between).
I'll look at doing something to display the host name and see whether there's a pettern there.
Peter
spraxyt
Superuser
Superuser
Posts: 10,063
Thanks: 1,369
Fixes: 75
Registered: ‎06-04-2007

Re: PHP start_session() running very slowly

Suspecting this problem has occurred for "a few months" is interesting. To try to be a little more precise, would you say that means 2 or 3 months, 5 or 6 months, or perhaps longer?
I think what you are experiencing is a problem with exclusive file access locks on the session file when multiple server hosts are involved. Since an flock function is built into PHP I assume session_start() uses that for setting its locks.
For a while I've had a similar problem, but with flock in Perl. In my case the lock is used to prevent two or more independent visitors to a page causing a file to be updated at the same time (and overwriting each others updates). In my case I think each visitor is likely to be served from a different host in the cluster.
At the moment Plusnet and Hostopia are playing ticket tennis with the support query. Hostopia failed to find any system change around the time the problem first occurred. Moreover they claim flock works with myself supplying hard evidence (even using their test case) that it doesn't. The problem manifests itself as 30 second delays in my tests for something that should complete in milliseconds. Necessarily Plusnet support are the intermediary between me and Hostopia but I must emphasise that Plusnet support has been exemplary through this saga.
My problem is with the Perl implementation so having a similar one with PHP is very useful. To this end if would be most helpful if you could create a simple test page showing test date and time, page loading times and the server hostnames involved.
David
David
bobpullen
Community Gaffer
Community Gaffer
Posts: 14,877
Thanks: 2,479
Fixes: 168
Registered: ‎04-04-2007

Re: PHP start_session() running very slowly

@Kiwi2, are you still relying on the same scripts and if so, how are they performing now? I've good reason to believe that things should have improved towards the end of March?

Bob Pullen
Plusnet Product Team
If I've been helpful then please give thanks ⤵