Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6132173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:04:07+00:00 2026-05-23T17:04:07+00:00

Why this dummy script keeps running event if the client closes the browser (so

  • 0

Why this dummy script keeps running event if the client closes the browser (so the connection to the server)?

while ( true )
{
    sleep( 1 );
    file_put_contents( '/tmp/foo' , "I'm alive ".getmypid()."\n" , FILE_APPEND );
}

It’s unexpected to me according to this. Also this example doesn’t seem to work.

And set_time_limit with a non-zero parameter simply does nothing.

I’d like some clarifications.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:04:07+00:00Added an answer on May 23, 2026 at 5:04 pm

    If you try to write some output to the browser in that loop, you should find the script aborts if the connection has been terminated. This behaviour is hinted at in the documentation for ignore_user_abort

    When running PHP as a command line script, and the script’s tty goes
    away without the script being terminated then the script will die the
    next time it tries to write anything, unless value is set to TRUE

    I tried a few experiments myself, and found that even if you do attempt some browser output, the script will keep running if the output buffer isn’t full yet. If you turn output buffering off, the script will abort when output is attempted. This makes sense – the SAPI layer should notice the request has been terminated when it tries to transmit the output.

    Here’s an example…

    //ensure we're  not ignoring aborts..
    ignore_user_abort(false);
    
    //find out how big the output buffer is
    $buffersize=max(1, ini_get('output_buffering'));
    
    
    while (true)
    {
        sleep( 1 );
    
        //ensure we fill the output buffer - if the user has aborted, then the script
        //will get aborted here
        echo str_repeat('*', $buffersize)."\n";
    
        file_put_contents( '/tmp/foo' , "I'm alive ".getmypid()."\n" , FILE_APPEND );
    }
    

    That demonstrates what triggers the abort. If you had a script which was prone to enter an endless loop with no output, you could use connection_aborted() to test whether the connection is still open.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a bit new to Javascript. I am writing this dummy script to
I'm trying to launch VLC in dummy mode from a Node.js server script, however
This is a dummy script : create table #tempLogs ( UserId int identity(1,1) primary
I have a generic method with this (dummy) code (yes I'm aware IList has
I fear this is probably a bit of a dummy question, but it has
This past summer I was developing a basic ASP.NET/SQL Server CRUD app, and unit
I have the following dummy test script: function test() { var x = 0.1
I'm implementing Comet using the script tag long polling technique, based on this page
I have been using this simple script to generate images from text: <?php header('Content-type:
I thought I knew how to declare javascript arrays but in this script I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.