Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #16874 > unrolled thread
| Started by | bit-naughty@hotmail.com |
|---|---|
| First post | 2016-07-24 00:51 -0700 |
| Last post | 2016-07-24 04:14 -0500 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.php
Connection between client and server bit-naughty@hotmail.com - 2016-07-24 00:51 -0700
Re: Connection between client and server "J.O. Aho" <user@example.net> - 2016-07-24 10:44 +0200
Re: Connection between client and server gordonb.88fwl@burditt.org (Gordon Burditt) - 2016-07-24 04:14 -0500
| From | bit-naughty@hotmail.com |
|---|---|
| Date | 2016-07-24 00:51 -0700 |
| Subject | Connection between client and server |
| Message-ID | <7685ed66-ee5e-46a0-aeba-0bd9b408d286@googlegroups.com> |
If I have a page which say, echo's something, and then does stuff on the server side, eg. putting something inside a database, say - I was thinking of *FIRST* doing the echo'ing, and THEN doing the "stuff" - which obviously means that if the server crashes between the echo and the stuff, the task won't get done. But I'm also wondering what happens if someone clicks off that tab or closes the browser as soon as they see the text (whatever's been echo'd) - will that kill the process on the server side? Before it's completed whatever it was supposed to do? How do I prevent this? Thanks.
[toc] | [next] | [standalone]
| From | "J.O. Aho" <user@example.net> |
|---|---|
| Date | 2016-07-24 10:44 +0200 |
| Message-ID | <dvjdeoFrv02U1@mid.individual.net> |
| In reply to | #16874 |
On 07/24/16 09:51, bit-naughty@hotmail.com wrote: > If I have a page which say, echo's something, and then does stuff on the server side, eg. putting something inside a database, say - I was thinking of *FIRST* doing the echo'ing, and THEN doing the "stuff" - which obviously means that if the server crashes between the echo and the stuff, the task won't get done. But I'm also wondering what happens if someone clicks off that tab or closes the browser as soon as they see the text (whatever's been echo'd) - will that kill the process on the server side? Before it's completed whatever it was supposed to do? How do I prevent this? The process should in most cases execute to the end, but still the best practice is to execute things first and then give the output, as this way you can tell that something went wrong and ask the user to redo the post. -- //Aho
[toc] | [prev] | [next] | [standalone]
| From | gordonb.88fwl@burditt.org (Gordon Burditt) |
|---|---|
| Date | 2016-07-24 04:14 -0500 |
| Message-ID | <IdmdnWRWlJ9rGwnKnZ2dnUU7-dXNnZ2d@posted.internetamerica> |
| In reply to | #16874 |
> If I have a page which say, echo's something, and then does stuff > on the server side, eg. putting something inside a database, say - > I was thinking of *FIRST* doing the echo'ing, and THEN doing the > "stuff" - which obviously means that if the server crashes between > the echo and the stuff, the task won't get done. But I'm also > wondering what happens if someone clicks off that tab or closes the > browser as soon as they see the text (whatever's been echo'd) - Check out the PHP ignore_user_abort(true) function. You may also need set_time_limit(). And flush() may be useful to get a "please wait" message out BEFORE the time-consuming stuff starts instead of after. DON'T make that message "thank you for purchasing blah blah blah". (You haven't even started to charge the credit card yet, anyway.) Make it more like "processing your order, please wait". > will that kill the process on the server side? Before it's completed > whatever it was supposed to do? How do I prevent this? Then, when it finishes, (optionally: turn off ignore_user_abort() after setting up the order and before generating the receipt), output a receipt for the order and invite the user to save it. The receipt should contain such things as an order number, user's name / account, the date, the amount charged, optionally what was ordered, and a link to where to see order status. Or maybe it's just "Your message has been successfully posted". Don't tell the user it's done until it's done. You can never know when your server will suffer a direct lightning hit, a bomb, or an 18-wheeler will knock down the pole containing your internet connection. Of course, lightning hits and bombs can kill orders entered the previous week (or perhaps decade). That's one reason for real-time replicated databases on different continents. I don't think *closing the browser* or *navigating away from the page* by itself causes an abort. What causes an abort happens when the browser discovers it can't deliver more data to the browser. Either way, the user won't see the output. But you do get to finish registering the transaction in a database. So: echo "Preparing to Frombulate ..\n"; flush(); /* ignore_user_abort(true); uncomment to avoid script halting */ /* user closes browser here or hits STOP */ ... Do the frombulation ... ... This takes half a minute ... echo "Halfway through the Frombulation ...\n"; flush(); <---- KABOOM!! Script aborts here. ... Clean up the frombulation ... echo "Frombulation complete.\n"; exit; The script doesn't stop until it generates and sends output *after* the browser gets closed. If the output is short, and you don't flush() to force it to be sent, it might not be sent until later.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web