I have a situation where I need to run some PHP, specifically where I need to send out a SOAP request and wait for the response, and then do something with that, however sometimes these requests can be slow and take up to 9 seconds.
Now I don't really want the user sitting there waiting 9 seconds for this to plete.
Basically the user flow is..
- User es to payment page
- User clicks button to pay via payment gateway (Paypal)
- User then returns to the site (SOAP request and all that need to be finished at this stage)
I was thinking of running it with the Paypal IPN notification but then didn't think it would be finished by the time the user got back to the site.
So, I'm wondering if I could send off a call when the user hits the first page via Ajax and have it run whilst the user is submitting payment and by the time they get back to the site it should be done -- it's not a big deal if they don't end up going through with payment, so I'm not worried about running this code before confirming payment.
My question is, if I fire this off to be run via AJAX, will the code still be executed if the user leaves the page before it has finished? If not, any ideas?
I have a situation where I need to run some PHP, specifically where I need to send out a SOAP request and wait for the response, and then do something with that, however sometimes these requests can be slow and take up to 9 seconds.
Now I don't really want the user sitting there waiting 9 seconds for this to plete.
Basically the user flow is..
- User es to payment page
- User clicks button to pay via payment gateway (Paypal)
- User then returns to the site (SOAP request and all that need to be finished at this stage)
I was thinking of running it with the Paypal IPN notification but then didn't think it would be finished by the time the user got back to the site.
So, I'm wondering if I could send off a call when the user hits the first page via Ajax and have it run whilst the user is submitting payment and by the time they get back to the site it should be done -- it's not a big deal if they don't end up going through with payment, so I'm not worried about running this code before confirming payment.
My question is, if I fire this off to be run via AJAX, will the code still be executed if the user leaves the page before it has finished? If not, any ideas?
Share Improve this question edited May 13, 2013 at 9:36 Niels Keurentjes 42k9 gold badges102 silver badges138 bronze badges asked May 13, 2013 at 9:11 BrettBrett 20.1k57 gold badges166 silver badges303 bronze badges 4- don't send them to paypal until the ajax is plete. – kennypu Commented May 13, 2013 at 9:13
- that way you can confirm that the ajax request was sent and received successfully with no problems. Also, say if you're sending the Ajax request and sending them to paypal at the sametime; you wouldn't want the ajax request to not send (because of the race condition) – kennypu Commented May 13, 2013 at 9:18
- @kennypu I'm not doing it at the same time. Once they enter the payment page the function will be run, they will then be able to click the payment button. :) – Brett Commented May 13, 2013 at 10:13
- in that case you shouldn't have to worry about anything, especially if you're not returning anything from the ajax request, only sending something. – kennypu Commented May 13, 2013 at 10:14
2 Answers
Reset to default 8Once a request is sent to the server, irrespective of whether you navigate away from the page the server side of the request will get pleted.
The only thing that will not happen is the execution of client side callback method.
If you are using php , there is a php.ini setting ignore_user_abort
that tells php what to do when the client aborts the request.
Its value is false by default.
http://www.php/manual/en/misc.configuration.php#ini.ignore-user-abort