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("Locatio n: please_wait.php ");
//do stuff that takes aaaaaages here
$_SESSION['stuff_to_displ ay']=$stuff_that_th e_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
7 7566 Motoma 3,237
Recognized Expert Specialist
Why not have your "Please wait" page do all of the processing?
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!
Hi,
Why dont you chacge the timeout settings in your php.ini file to a higher timeout value??
Regards
CyberKing
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_stuf f.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("Locatio n: 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()<$t ime)
{
//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.ph p':
[HTML]<html><head>
<meta http-equiv="Refresh" content="2; url=results.php ">
</head><body>
Please wait while we do stuff
</body></html>
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($_SES SION['textbox'])) //if the data is NOT yet ready
{
header("Locatio n: 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.
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("Locatio n: please_wait.php ");
session_start() ;
//then whitespace
?>
<?php
while (@ob_end_flush( ));
while (@flush());
session_write_c lose();
//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()<$t ime)
{
//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_c lose(); //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!!!
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!
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 contains:
<?php
$_SESSION = "";
$_SESSION = "";
|
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
including the php.net manual.
In the manual it said to include something like the following:
|
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 the
DB I am using a DIV with a please wait message which is removed once
the page is loaded.
In addition I am using a global error handling using the
Application_Error void in the Global.asax file.
when the application is loading a page which...
|
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 on my
Citrix servers for usage tracking purposes.
The service itself seems to function properly, it starts, stops, logs
to the event viewer, etc. The problem seems to be with the portion
where it either waits to be stopped or waits for remote...
|
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 that he wants me to do
something through which only one user can login using any
given account name. I mean to say, for example, when a
user called "abc" is online, another person shouldn't be
| |
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) cookie
is created to hold the session key for the user. This unique key is
assigned as part of the business layer logon process, and never changes
while the user is logged on. The call to the business component returns
this unique key if the logon...
|
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 object of session class. I am creating this
object in the login page.
Now how can i make this object persist between subsequent page
requests. and i dont want to use GET method.
Is it sensible to use hidden fields OR will i have to create a new
|
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?
|
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* image requests
to a Php script that checks for that variable before simply delivering
the image. Direct links to my images will fail this test and no image
is served.
I am monitoring my script by sending emails to myself and finding that...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |