Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Slow session_start()

Status
Not open for further replies.

deepsheep

Programmer
Sep 13, 2002
154
CA
I have a newly built webserver using Ubuntu Linux and php 5.2.10. Everything seems to work well, but the session_start is painfully slow. It works, but seems to take 2 minutes. I tested on IE and FF and on a couple computers with the same results.

I've search the internet and come up with issues with the server's file system. So we removed Samba and found we're using ext4. I've even tried cookies_only with no luck.

Any more ideas? It's the only thing keeping me from completing by project.
 
Are you using the default session handlers i.e. are you using /tmp for the files ?
If so how slow is that if you create a file there ?
If not where are you storing the session data ?
 
here's the php_info section. everything looked ok to me.

session

Session Support enabled
Registered save handlers files user sqlite
Registered serializer handlers php php_binary

Directive Local Value Master Value
session.auto_start Off Off
session.bug_compat_42 On On
session.bug_compat_warn On On
session.cache_expire 180 180
session.cache_limiter nocache nocache
session.cookie_domain no value no value
session.cookie_httponly Off Off
session.cookie_lifetime 0 0
session.cookie_path / /
session.cookie_secure Off Off
session.entropy_file no value no value
session.entropy_length 0 0
session.gc_divisor 100 100
session.gc_maxlifetime 1440 1440
session.gc_probability 1 1
session.hash_bits_per_character 4 4
session.hash_function 0 0
session.name PHPSESSID PHPSESSID
session.referer_check no value no value
session.save_handler files files
session.save_path /var/lib/php5 /var/lib/php5
session.serialize_handler php php
session.use_cookies On On
session.use_only_cookies On On
session.use_trans_sid 0 0


as an added gotcha.... I had the server admin reset the server and it's fast right after, but it keeps getting slower... But we did that yesterday and it got very slow after an hour or so.
Before you say "too much load", I'm the only one using it.
 
Can you change /var/lib/php5 to /tmp ?
plus are you sure it's session_start() causing the slowness ?
 
if it's getting slow then something is going on by way of processes (most likely). when you notice a slow down analyse the currently active processes and how much memory they are taking.
 
There a few references to NTFS making session_start() act slow. I had a quick look at the source and the session_start() doesn't seem to access file store, seems that happens when you actualy write something away. Maybe wrong on this I only looked very quickly.
An interesting issue none the less !
 
session_start will access the file store on a read operation, if the file exists.
it is the explicit or implicit session_write_* that causes the file write operation (so far as I understand anyway).

I do recall older file systems having problems with large numbers of files in a directory, but surely not the issue in this case as the OP says it is only him using it. there should only be one session file (unless he is using it from multiple browsers or regenerating session_ids for each access. in these cases, perhaps decreasing the session longevity and increasing the garbage collection probability might clear things out.

another alternative is if he is storing stuff iteratively in the session store for each access. i.e. if the session file grows each access than, inevitably, the time to read and unserialise the session data will increase each access.

 
I've seen other posts on the internet with the same issue, but no solution. So it is a curious problem!

Well, I watched processes and didn't see anything overly weird.
I tried an assortment of destroying sessions, closing sessions and similar, thinking that maybe there was an existing session and things were getting confused, even though it shouldn't. Didn't do any thing.
I've searched the internet to ensure I wasn't missing a step, and it all looked ok.
At a previous job, I've set up php sessions on a windows machine and they worked fine. So I know it's not too hard.

A few things I did observe:
It's fast after a server restart.
It's fast after leaving it for a time. I didn't get a timespan though.
Closing/reopening the browser doesn't seem to matter for speed, even though it matters for sessions.
Sometimes it's fast for one login attempt, sometimes more. But it always slows down again.

Between me and the server admin, we figure the problem has GOT to be with the file access in the Linux install. And then he inadvertantly borked the users. So he's redoing the entire server right now.

When the server is up and running, I'll do some more testing and let you know the results. I'm hoping it will just work!
 
Windows :)
What would be usefull to knoow is what happends when you use /tmp and also what happens if you try to create a file on /var/lib/php5 (just using shell facilities) from the user that the PHP process will run under.
I think you have to first establish whether it is the filestore which physicaly slow.
Just going back to the session internals. I won't get a chance this week to look more in depth but it would be useull to get a better handle on what is going on. I you have a look at the source it looks at cookies and if the session doesn't exist it won't read the filestore (can't remember what it said about SID in the query string). In any case I can't think that the session code is wrong after all it is used on a large number of sites.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top