473,480 Members | 2,123 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

session_start hangs parallel requests for the same session

Hi. I have a session started in php and two browser windows (IE)/tabs
(FF) open.
In one window, I execute a very slow report, immediately after that, I
execute a fast simple page in another.

I have set up a timer that records time into global variable at the
start of the request,
it outputs three time values in seconds - right before session_start,
right after session_start, and at the very end of the request.
here's what it shows
Slow report that started a second earlier:
DEBUG: Before session start: 0.0115
DEBUG: Session start: 0.0133
DEBUG: End request: 101.9878

"Quick" page that started after it:
DEBUG: Before session start: 0.0114
DEBUG: Session start time: 98.467
DEBUG: End request: 99.084

The same is true for any request count, all of them load as fast as
the slowest one.
What's wrong w/session_start and how do I fix it?

Jun 11 '07 #1
14 9294
On Jun 11, 12:21 pm, Sergei Shelukhin <realg...@gmail.comwrote:
Hi. I have a session started in php and two browser windows (IE)/tabs
(FF) open.
In one window, I execute a very slow report, immediately after that, I
execute a fast simple page in another.

I have set up a timer that records time into global variable at the
start of the request,
it outputs three time values in seconds - right before session_start,
right after session_start, and at the very end of the request.
here's what it shows
Slow report that started a second earlier:
DEBUG: Before session start: 0.0115
DEBUG: Session start: 0.0133
DEBUG: End request: 101.9878

"Quick" page that started after it:
DEBUG: Before session start: 0.0114
DEBUG: Session start time: 98.467
DEBUG: End request: 99.084

The same is true for any request count, all of them load as fast as
the slowest one.
What's wrong w/session_start and how do I fix it?
It's because the first request locks the session file and doesn't
release the lock until the session is closed (at the end of the
request). So, the other pages wait for it to finish. See this note:

<http://www.php.net/manual/en/ref.session.php#64525>

Jun 11 '07 #2
Thanks, that was it!
However, if I have a standard pattern where session is started and
then closed for writing at the start of every request in one place,
how do I reopen it to write a variable once in a while? I have exactly
two places where I need to do that and if I use session_start there it
shows warnings (cannot send cookie). I can suppress them but it
doesn't seem right

Jun 11 '07 #3
Sergei Shelukhin wrote:
Hi. I have a session started in php and two browser windows (IE)/tabs
(FF) open.
In one window, I execute a very slow report, immediately after that, I
execute a fast simple page in another.

I have set up a timer that records time into global variable at the
start of the request,
it outputs three time values in seconds - right before session_start,
right after session_start, and at the very end of the request.
here's what it shows
Slow report that started a second earlier:
DEBUG: Before session start: 0.0115
DEBUG: Session start: 0.0133
DEBUG: End request: 101.9878

"Quick" page that started after it:
DEBUG: Before session start: 0.0114
DEBUG: Session start time: 98.467
DEBUG: End request: 99.084

The same is true for any request count, all of them load as fast as
the slowest one.
What's wrong w/session_start and how do I fix it?
Sessions are single threaded. If you already have the page open in one
session, PHP will hold any other requests for that same session.

To resolve the problem you need to call session_write_close() in the
long-running task. Of course, after that you won't have access to any
of the $_SESSION variables.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 11 '07 #4
Sergei Shelukhin wrote:
Thanks, that was it!
However, if I have a standard pattern where session is started and
then closed for writing at the start of every request in one place,
how do I reopen it to write a variable once in a while? I have exactly
two places where I need to do that and if I use session_start there it
shows warnings (cannot send cookie). I can suppress them but it
doesn't seem right
You don't. Once you close the session, you can't open it again in the
same request.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 12 '07 #5
Eh... How do I fiox the problem and write into session then? Do I have
to write into session files manually?

Jun 20 '07 #6
Sergei Shelukhin wrote:
Eh... How do I fiox the problem and write into session then? Do I have
to write into session files manually?
You can't. It's simply a restriction of how sessions work.

Also, you can't write the session file itself manually, either - if you
tried, results would be highly indeterminate, IMHO.

Maybe you need to use another means to store your data (like an RDB) and
pass the id in the session.

Or perhaps you need to look at how to restructure your code.

But this will only affect someone if they have your site open in two
browser windows (and the same browser - not different browsers).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 20 '07 #7
Well as a matter of fact it's not a site, it's an intranet app, 99% of
all users open it in multiple tabs and it's bad that session is
basically unusable in php 0_o
I wonder if they are going to fix it in php 6?

Jun 24 '07 #8
Sergei Shelukhin wrote:
Well as a matter of fact it's not a site, it's an intranet app, 99% of
all users open it in multiple tabs and it's bad that session is
basically unusable in php 0_o
I wonder if they are going to fix it in php 6?
It's not just a PHP issue. It also has to do with Apache, the OS, and
HTTP protocol and the browser. As other languages have the same
"problem", I doubt it will be "fixed" because it's not broken.

And sessions are quite useful in PHP. I use them all the time, and so
do every PHP programmer I know. They just can't be used like you want
them to be used.

As I said - find another way to do it. For instance, use a database and
keep the key to the row in the session.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 24 '07 #9
Huh? ASP.NET doesn't have this problem, and neither does ASP. As far
as I remember Perl doesn't have this problem either, I don't remember
how I stored the session back then tho. If for example I want to store
some token between several pages it's pretty impractical to do so in a
database, taking care of the timeout/cleanup and uniqueness code too,
the fact that there's a variable that either locks up parallel
requests or is readonly is pretty illogical from my fresh point of
view :)

The strangest thing is that the app I'm now maintaining and improving
was written by an actual PHP programmer who used session in this way
and somhow tricked users into believing that slow search query locking
up their profile editing is ok 0_o

Jun 25 '07 #10
Sergei Shelukhin wrote:
Huh? ASP.NET doesn't have this problem, and neither does ASP. As far
as I remember Perl doesn't have this problem either, I don't remember
how I stored the session back then tho. If for example I want to store
some token between several pages it's pretty impractical to do so in a
database, taking care of the timeout/cleanup and uniqueness code too,
the fact that there's a variable that either locks up parallel
requests or is readonly is pretty illogical from my fresh point of
view :)

The strangest thing is that the app I'm now maintaining and improving
was written by an actual PHP programmer who used session in this way
and somhow tricked users into believing that slow search query locking
up their profile editing is ok 0_o
Hmmm, you're right - ASP doesn't lock it. But then ASP has known
problems with session corruption when the session is being accessed by
multiple windows. I can only assume ASP.NET, if it works the same way,
has the same problem.

And IIRC, Perl also has a problem with multiple windows accessing the
same session. But the last time I had that problem was a while ago;
most of my new programming is in PHP nowadays. So perhaps that
"problem" has been fixed.

And you can store them in a database or you can store them in a file
(PHP's default).

Or, if you can't stand the way PHP handles sessions, you can, of course,
use a different language.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 26 '07 #11
Umm, my last post was not intended for creating usual php vs asp
flame, but for clarification, ASP.NET doesn't have session corruption
problems for any storage mechanism available; for default in-proccess
session the session (but not auth) "goes away" if something like web
server restart happens, persistent storage doesn't have this problem
too. And I never knew of any session corruption problems in ASP 3.0
and never experienced it in my apps.

Then, I cannot use another language - I have to use PHP for this
project.

Jun 28 '07 #12
Sergei Shelukhin wrote:
Umm, my last post was not intended for creating usual php vs asp
flame, but for clarification, ASP.NET doesn't have session corruption
problems for any storage mechanism available; for default in-proccess
session the session (but not auth) "goes away" if something like web
server restart happens, persistent storage doesn't have this problem
too. And I never knew of any session corruption problems in ASP 3.0
and never experienced it in my apps.

Then, I cannot use another language - I have to use PHP for this
project.
I have seen session corruption in .ASP. It's timing related, but it
does happen.

And if you have to use PHP, then I suggest you stop complaining and get
to programming. This is how PHP works. You want it to work another
way? Use another language.

Much of it has to do with the fact PHP stores its session data on the
file system. Among other things, this can help by surviving a webserver
restart. But it also means only one thread can have the file open at a
time.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 28 '07 #13
Well, I wonder if I could suggest a fix?
"But it also means only one thread can have the file open at a time."
- the solution for this is implied in one of the posts where I was
still unsure about how it works - a thread could open the file
exclusively, write to it, and then unlock it; reading could be done
without locking the file (if the file is currently locked then there
should be a reasonable/configurable timeout).

E.g. a standard reader-writer lock pattern.


Jul 2 '07 #14
Sergei Shelukhin wrote:
Well, I wonder if I could suggest a fix?
"But it also means only one thread can have the file open at a time."
- the solution for this is implied in one of the posts where I was
still unsure about how it works - a thread could open the file
exclusively, write to it, and then unlock it; reading could be done
without locking the file (if the file is currently locked then there
should be a reasonable/configurable timeout).

E.g. a standard reader-writer lock pattern.

By definition, if you open a session, you open it for both reading and
writing.

If you only want it open for reading, it's simple. Open the session,
cache the data you need then close the session.

Or use a different language. This is how PHP works. And you aren't
going to be able to change it.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 2 '07 #15

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
11122
by: Chris Allen | last post by:
Hi I'm new to PHP and I'm trying to create a Login Form. Once the user has logged in then he shouldn't have to log in again. The trouble is I'm getting a new session ID between every page and so...
0
1297
by: mmf | last post by:
Hi! I am using Python for CGI scripting. I had the following script: #!/usr/bin/python import sys print 'Content-type: text/html\r\n\r\n' print 'starting...' sys.stdout.flush() x = 999999
5
2341
by: Ken Barrett | last post by:
I apologize in advance for cross-posting, but I have noted that others have experienced similar issues and was hoping that someone could help. Briefly, I am working on an ASP.NET content...
2
1415
by: Jeff S | last post by:
My intent is to write some information to a database when a new session of my application begins. The code that writes to the database works great - however the Session_Start procedure (in...
2
3379
by: Jeanne Louw | last post by:
Hi Why would this happen? The Application_Start and Session_Start events fires on each page request on my website. SessionID stays the same between page requests. <sessionState mode="InProc"...
5
2158
by: Niklas Uhlin | last post by:
Someone please explain why Session_Start fires multiple times / retains SessionID values between sessions, when you open an ASP.NET page from MS Word. For details of the problem, see below: 1....
9
2280
by: a | last post by:
I already posted on this subject, but I have some more information that should make the issue clearer. Config: Apache 2.x, PHP 5.1.x, Windows XP Pro A php script processes a form. Inside this...
4
2534
by: Christoph | last post by:
A while ago, I implemented an AJAX-based progress bar on a web page that executed a lengthy server operation. The web page was a Java servlet on a Tomcat server. The progress bar worked by...
7
3133
by: =?Utf-8?B?Vkg=?= | last post by:
Hi, all. Need help with what seems to be either connection, or threading problem in my ASP.NET 2.0 application. The gist of the problem is this: IHttpHandler in my application serves an HTML...
0
6911
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7091
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6743
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5344
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2999
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2988
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
564
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.