Does all php code finish executing

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
robble
Forum Newbie
Posts: 11
Joined: Fri Aug 24, 2007 6:34 am

Does all php code finish executing

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Does all php code finish executing

Post 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.
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post 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.
robble
Forum Newbie
Posts: 11
Joined: Fri Aug 24, 2007 6:34 am

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

robble wrote:Interesting potential to run cron jobs.
You've already had a discussion about it :)
viewtopic.php?t=72594
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply