Apache Server configuration support - Reentrant POST

This is Interesting: Free IT Magazines  
Home > Archive > Apache Server configuration support > February 2006 > Reentrant POST





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Reentrant POST
a

2006-02-08, 3:02 am

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


John Smith

2006-02-08, 7:50 am

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


a

2006-02-08, 5:59 pm

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.




John Smith

2006-02-13, 7:50 am

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


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com