Reentrant POST

This is a discussion on Reentrant POST within the Apache Web Server forums, part of the Web Server and Related Forums category; Hi, I posted the same question on the comp.lang.php group, but didn't get an answer, so I'...


Go Back   Usenet Forums > Web Server and Related Forums > Apache Web Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-08-2006
a
 
Posts: n/a
Default Reentrant POST

Hi,

I posted the same question on the comp.lang.php group, but didn't get an
answer, so I'm trying here.

My config: Apache 2.x with PHP 5.1.x running on WinXP Pro.

I have a php script that handles a form as result of a POST. The php script
starts a windows process (in fact it asks a windows service to start the
said process, for security reasons) which may take a long time to complete.
In the meantime the user sees the hourglass in the browser. If the user
presses submit again during this time on the same form, Apache hangs and
eventually crashes.

My questions:
- how does Apache handle this kind of situation, does it try to start
another instance of the same script, or does it wait until the current
processing ends...?
- how can I handle such reentrant requests from the user, to avoid the
server crash and to give the user more control over whether to restart or
cancel the processing

Thanks,

A


  #2 (permalink)  
Old 02-08-2006
John Smith
 
Posts: n/a
Default Re: Reentrant POST

I'd suggest setting a session variable on your form target eg :-

if (!isset($_SESSION['loading']))
{
$_SESSION['loading']=true;
/*
Do what ever else you want to do first time here
*/
}
else
{
echo "<p>Your Request is already in progress. Please be patient!!!</p>";
}

Remember to unset the session var though afterwards??

Mind you, you could always target the form submission to an iframe and hide
the submit button with some Javascript
(document.form[0].submit.style.display='none')
Scott.
Hello, a!
You wrote on Wed, 08 Feb 2006 04:04:47 GMT:

a> I posted the same question on the comp.lang.php group, but didn't get an
a> answer, so I'm trying here.

a> My config: Apache 2.x with PHP 5.1.x running on WinXP Pro.

a> I have a php script that handles a form as result of a POST. The php
a> script starts a windows process (in fact it asks a windows service to
a> start the said process, for security reasons) which may take a long time
a> to complete. In the meantime the user sees the hourglass in the browser.
a> If the user presses submit again during this time on the same form,
a> Apache hangs and eventually crashes.

a> My questions:
a> - how does Apache handle this kind of situation, does it try to start
a> another instance of the same script, or does it wait until the current
a> processing ends...?
a> - how can I handle such reentrant requests from the user, to avoid the
a> server crash and to give the user more control over whether to restart
a> or cancel the processing

a> Thanks,


With best regards, John Smith. E-mail: someone@microsoft.com


  #3 (permalink)  
Old 02-08-2006
a
 
Posts: n/a
Default Re: Reentrant POST

Thanks for your helpful reply.

If I understand correctly then, when the user presses Submit in the form a
second time, a new instance of the script will be started (in a new CPU
thread I assume), even if the first one is still running. If that's the
case, it will be much easier then to implement a more user friendly
behavior, involving work in progress feedback and cancel capabilities.

Thanks,

A


> I'd suggest setting a session variable on your form target eg :-
>
> if (!isset($_SESSION['loading']))
> {
> $_SESSION['loading']=true;
> /*
> Do what ever else you want to do first time here
> */
> }
> else
> {
> echo "<p>Your Request is already in progress. Please be patient!!!</p>";
> }
>
> Remember to unset the session var though afterwards??
>
> Mind you, you could always target the form submission to an iframe and
> hide the submit button with some Javascript
> (document.form[0].submit.style.display='none')
> Scott.




  #4 (permalink)  
Old 02-13-2006
John Smith
 
Posts: n/a
Default Re: Reentrant POST

I'm sorry, I wrongly assumed you would understand the logic and syntax being
used. I do apologise if I didn't make it clear the first time. Perhaps a
plain english verison will clarify.

When the user hits Submit the first time your form processor(your .php page)
will set a flag (Session Var) then start your background process(or do
whatever else you tell it to).

If the user hits submit again (before the background process has completed)
the the form processor will see that it's a duplicate request and ignore the
second (and or subsequent) requests.

Once you background process has been finalised you should make sure your
Session Var is unset so future requests can be handled.

I'm not sure how your idea of new cpu threads fits in, it's purely a logical
structure and has nothing to do with threads or cpu's.

Scott

Hello, a!
You wrote on Wed, 08 Feb 2006 15:35:55 GMT:

a> If I understand correctly then, when the user presses Submit in the form
a> a second time, a new instance of the script will be started (in a new
a> CPU thread I assume), even if the first one is still running. If that's
a> the case, it will be much easier then to implement a more user friendly
a> behavior, involving work in progress feedback and cancel capabilities.

a> Thanks,

a> A

??>> I'd suggest setting a session variable on your form target eg :-
??>>
??>> if (!isset($_SESSION['loading']))
??>> {
??>> $_SESSION['loading']=true;
??>> /*
??>> Do what ever else you want to do first time here
??>> */
??>> }
??>> else
??>> {
??>> echo "<p>Your Request is already in progress. Please be
??>> patient!!!</p>"; } Remember to unset the session var though
??>> afterwards?? Mind you, you could always target the form submission to
??>> an iframe and hide the submit button with some Javascript
??>> (document.form[0].submit.style.display='none') Scott.


With best regards, John Smith. E-mail: someone@microsoft.com


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:18 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0