473,511 Members | 9,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using sessions, and 'please wait' pages

93 New Member
Hi, I'm building a site where the user enters some info into a form which submits to a php script. The php script takes a long time to execute (anywhere from 10 seconds to a minute) and when it finally finishes the page that it creates appears to get blocked by any firewall (tried on lots of different browsers/platforms) and you just get a completely blank page. (It's fine when just running on my local machine.)

I'm guessing that the script takes so long to execute that either the connection gets dropped (keep-alive timeout is set to 5, and I can't change it) or the firewall rejects the incoming data because the outgoing request was so long ago that it's forgotten about it.

I'm thinking that the solution is to use a 'please wait' page. So the user submits the form to my script, my script then sends back a session cookie along with a "Location: please_wait.php" header to redirect the user to the 'please wait' page. Whilst they're waiting, my php script does all its processing and sticks the info to be displayed into the $_SESSION array. The please wait page contains a <meta> tag that refreshes (after a few sceonds) to a php script that gets the info from the $_SESSION array and displays it.

And here's the question (at last!!)....
How do I get my script to send the session cookie and the "Location: " header, and THEN do it's processing? At the moment the form submits to a script like this:

[PHP]session_start();
header("Location: please_wait.php");

//do stuff that takes aaaaaages here

$_SESSION['stuff_to_display']=$stuff_that_the_script_made;[/PHP]
But the problem with it is that it doesn't send the header until it has done the processing. How do I get it to send the header and session cookie, and then do the processing? I've tried putting session_commit(); after the header(); line, but it doesn't help.

Any alternative solutions welcome as well.
Thanks
May 31 '07 #1
7 7554
Motoma
3,237 Recognized Expert Specialist
Why not have your "Please wait" page do all of the processing?
Jun 1 '07 #2
adamalton
93 New Member
Surelly that would still have the same problem?... The 'please wait' page would not get sent to the user's browser until it had done the processing. So by the time they got the 'please wait' page they wouldn't need to wait anymore!
Jun 1 '07 #3
cyberking
84 New Member
Hi,
Why dont you chacge the timeout settings in your php.ini file to a higher timeout value??
Regards
CyberKing
Jun 1 '07 #4
adamalton
93 New Member
The script is not timing out. Like I said, it works fine running on my local machine, and all the ini settings are the same on my webhost, and I'm not getting a timeout notice.

I've now got as far as getting my script to redirect the user to the 'please_wait' page and THEN do its processing. That seems to work. But the time that my script takes to do its processing can vary a lot. So I need the 'results' page to check to see if the processing has finished yet, and if it has NOT then redirect the user back to the please wait page again to wait for a few more seconds, or if the processing HAS finished then display the information. So the user just gets bounced back to the please wait page as many times as is necessary until the processing is done.

I've created some basic scripts to test this idea....

My page with the form on it:
[HTML]<form action="do_stuff.php" method="post">
<input type="text" name="textbox">
<input type="submit" value="go"></form>[/HTML]

'do_stuff.php':
[PHP]//redirect the user to the please wait page:
header("Location: please_wait.php");
session_start(); //that sets the session cookie
//then lots of whitespace to make the browser display the page (see the 'flush' page of the php.net manual)
?>




<?php
//send all of the output so far, so that the user goes to the please wait page
while (@ob_end_flush());
while (@flush());

//now do some processing that takes a long time!
$time=time()+15;
while(time()<$time)
{
//do nothing
}
//and when that's done some data will be created:
$_SESSION['textbox']=$_POST['textbox'];[/PHP]


And then the please wait page will redirect itself after 2 seconds;
'please_wait.php':
[HTML]<html><head>
<meta http-equiv="Refresh" content="2; url=results.php">
</head><body>
Please wait while we do stuff
</body></html>
Jun 1 '07 #5
adamalton
93 New Member
Dammit!! My posts never post properly. Half of that is missing! I think there's some kind of crap that happens when I copy and paste from dreamweaver to Firefox. It thinks that the end of the pasted text is the end of the post. Anyway, now I have to rewrite half of that again!...

So....

'results.php' is like this:
[PHP]session_start(); //get the user's session id so that $_SESSION works

if(!isset($_SESSION['textbox'])) //if the data is NOT yet ready
{
header("Location: please_wait.php"); //redirect them again
//more whitespace so that the browser will stop waiting for more stuff
?>





<?php
//send everything so far
while (@ob_end_flush());
while (@flush());
}
else //if the data IS ready
{
print "Your results are ready<br><br>";
print "You entered ". $_SESSION['textbox'];
}[/PHP]

The problem is that 'results.php' never redirects you back to the please wait page, even if the data isn't ready...it just waits until the data is ready and then sends it. I.e. php seems to know that $_SESSION is still in use in 'do_stuff.php' so instead of the isset() returning false, it waits until 'do_stuff.php' is finished, and then it returns true. Which is totally useless!

I need another way of checking to see if 'do_stuff.php' has finished processing.
Jun 1 '07 #6
adamalton
93 New Member
And 2 minutes after I spent all that time typing...I've done it!!!

No 2 scripts can write to the same session at once. So 'do_stuff.php' needs to be like this:[php]
header("Location: please_wait.php");
session_start();
//then whitespace
?>


<?php
while (@ob_end_flush());
while (@flush());

session_write_close();
//so this script is now done with the current session so that other scripts can access $_SESSION

//now do some processing that takes a long time!
$time=time()+15;
while(time()<$time)
{
//during this time any other script can access $_SESSION because this script is NOT using it (so 'results.php' can check isset($_SESSION)
}

//and now that we're done processing..
session_start(); //open the session up again
$_SESSION['textbox']=$_POST['textbox']; //stick the data in
session_write_close(); //and close it again (actually not necessary cos the session will be close when this script ends anyway)[/PHP]

I hope this saves someone else some time!!!
Jun 1 '07 #7
Motoma
3,237 Recognized Expert Specialist
Glad you figured out your problem. Sorry we did not fully understand your issue. thanks for posting the solution for the rest of the community!
Jun 1 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
5924
by: Paul | last post by:
I want to use sessions to cover myself in case the user switches off cookies so I am passing the session ID manually through a hidden input field. This is what I have so far. index.php page...
7
7486
by: John | last post by:
Hello. I want to get this blasted .htaccess file sorted out, so I can have sessions without register_globals being on. I have looked everywhere for info on this and I mean everywhere...
0
1969
by: s_erez | last post by:
Hi, This is a realy tricky one. I have an ASP.NET application where some pages are reading data from a DB and presenting reports. In order for the user to wait while the page is reading data from...
1
2216
by: JDF | last post by:
I am fairly new to python and seem to have gotten ahead of myself. I am trying to write a Windows service that will return the current number of Citrix sessions to a client. This service will run...
5
2062
by: Michelle Stone | last post by:
Hi everybody I am writing a simple asp.net application using form authentication. I store the list of all users and their passwords in an SQL Server database table. My client recently told me...
1
2272
by: AnthonyC | last post by:
I am having a problem tracking down what I believe to be a problem with the way cookies are being used on our website application. When user log onto the application, an in-memory (per-session)...
9
1522
by: viz | last post by:
hi, i have written a class for session handling, and i want to use it to keep track of the user. After authenticating the user in login page i am storing the session info like uname etc.. in a...
8
5766
by: Victor | last post by:
Can I get the events in GLOBAL.ASAX to fire if a classic ASP page is being accessed by the user?
8
2742
by: Chuck Anderson | last post by:
I've instituted a sessions based scheme on my web site to combat hot linking to my images. When someone requests a page at my site, I set a session variable. I then use htaccess to redirect *all*...
0
7251
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7148
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
7430
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
7089
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
5673
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
4743
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
3230
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
3217
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
451
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.