Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts

    Does Script still run

    Say i have a php cron script that runs for 10 mins. If i run that script from a web browser and then close the browser down halfway through the script completing. Would the script continue to run in the background? Or does the script stop when i close the browser window down?
    You can not say you know how to do something, until you can teach it to someone else.

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    It'll stop when the script completes or exits. The browser state is irrelevant once the script is called, unless further user input is required.

  • Users who have thanked MattF for this post:

    timgolding (06-15-2010)

  • #3
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    I don't think the answer is that straightforward.

    http://us.php.net/manual/en/function...user-abort.php
    Are you a Help Vampire?

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Default it will terminate when a user closes their browser, unless ignoring the user abort as tomws posted a link to.
    Command line behaviour is different, it should work indefinitely until:
    1. Script completes.
    2. Allocated memory to PHP is exhausted.
    3. Allowed time for PHP is exceeded.
    4. Process is terminated.
    5. In the event that memory allocation is infinite:
      • All available memory is exhausted
    6. In the event that time allowed is infinite
      • Script will not terminate by cause of time.


    Most terminations from a user are ignored though, but not by PHP/Apache. This is simply because we send request to the server via stateless protocol, and it has no idea if we're still listening, so it simply throws it back to us. If we don't respond, it only tries a couple more times and then gives up (this is the communication though, still not PHP/Apache).

    The only way to really see the disconnection behaviour is to run an infinite loop with some flushes. Upon termination by checking for connection status, write output to a file (pretty much the same as the example in the ignore user abort page actually, except we added a file write). I believe this also qualifies if a user hits the stop button on an infinite script.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    timgolding (06-16-2010)

  • #5
    Senior Coder timgolding's Avatar
    Join Date
    Aug 2006
    Location
    Southampton
    Posts
    1,517
    Thanks
    114
    Thanked 110 Times in 109 Posts
    Thanks that explains a lot.
    You can not say you know how to do something, until you can teach it to someone else.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •