Page 1 of 1

Does all php code finish executing

Posted: Fri Aug 24, 2007 6:55 am
by robble
Hi, sorry if i'm in the wrong forum but I think it goes here although probably a very simple question...

If I load a php page and close it before its finished loading, will the server still execute all the php code? - I thought it didnt but need confirmation.

I know I could test this to a degree but what i'm thinking is:

If it doesnt finish executing all code, does it at least finish the function its on, what if its in the middle of a file write (although I know more or less how temp files / dirs are handled). If it stops at a certain place in the code, where does it decide to stop executing? I've tried googling but I think my search terms must be way too innacurate for what i'm actually trying to ask...

Thanks

Robble

Re: Does all php code finish executing

Posted: Fri Aug 24, 2007 7:09 am
by superdezign
robble wrote:If I load a php page and close it before its finished loading, will the server still execute all the php code? - I thought it didnt but need confirmation.
I don't believe so, not automatically. I think you need to specify to PHP that you want it to continue.

Posted: Fri Aug 24, 2007 7:28 am
by stereofrog
From my understanding, php (or, rather, apache) can only detect broken connection when it tries to send something to the client. In other words, the "connection aborted" event can only happen after explicit or implicit "echo" in your script.

See also ignore_user_abort in the manual.

Posted: Fri Aug 24, 2007 9:23 am
by robble
Thanks for the info :), ignore_user_abort() is exactly what I needed, this will allow the script to run through even if the user has cancelled the page. Interesting potential to run cron jobs.

Posted: Fri Aug 24, 2007 9:28 am
by VladSun
robble wrote:Interesting potential to run cron jobs.
You've already had a discussion about it :)
viewtopic.php?t=72594