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

  • SEARCH
  • Home
  • 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 8438491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:43:59+00:00 2026-06-10T07:43:59+00:00

This question came up to me when I encountered a bug that caused my

  • 0

This question came up to me when I encountered a bug that caused my PHP program to loop infinitely. Here is an example situation:

Suppose I have a PHP webpage that receives picture uploads (the page perhaps is a response page for an image upload form). In the server, the script should store the image in a temporary file. The script should then output a confirmation message to the client then stop sending data so that the client would not wait. The script should then continue executing, processing the image (like resizing it) before ending.

I think this “technique” could be useful such that the client will not wait during time-consuming processes, therefore preventing time-outs.

Also, could this be solved using HTTP methods?

  • 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-06-10T07:44:00+00:00Added an answer on June 10, 2026 at 7:44 am

    Yes.

    This can easily be done without any asynchronous processing if you correctly utilize HTTP headers.

    Under normal conditions PHP will stop processing as soon as the client on the other end closes the connection. If you want to continue processing after this event, you need to do one thing: tell PHP to ignore user aborts. How?

    ignore_user_abort()

    This will allow your script to keep running even after the client gets the heck out of dodge. But we’re also faced with the problem of how to tell the client that the request they made is finished so that it will close the connection. Normally, PHP transparently handles sending these headers for us if we don’t specify them. Here, though, we need to do it explicitly or the client won’t know when we want them to stop reading the response.

    To do this, we have to send the appropriate HTTP headers to tell the client when to close:

    Connection: close
    Content-Length: 42
    

    This combination of headers tells the client that once it reads 42 bytes of entity body response that the message is finished and that they should close the connection. There are a couple of consequences to this method:

    1. You have to generate your response BEFORE sending any output because you have to determine its content length size in bytes so you can send the correct header.
    2. You have to actually send these headers BEFORE you echo any output.

    So your script might look something like this:

    <?php
    
    ignore_user_abort();
    
    // do work to determine the response you want to send ($responseBody)
    $contentLength = strlen($responseBody);
    
    header('Connection: close');
    header("Content-Length: $contentLength");
    flush();
    
    echo $responseBody;
    
    // --- client will now disconnect and you can continue processing here ---
    

    The big "Gotchya" with this method is that when you’re running PHP in a web SAPI you can easily run up against the max time limit directive if you do time-consuming processing after the end user client closes the connection. If this is a problem, you may need to consider an asynchronous processing option using cron because there is no time limit when PHP runs in a CLI environment. Alternatively, you could just up the time limit of your scripts in the web environment using set_time_limitdocs.

    It’s worth mentioning that if you do something like this, you may also want to add a check to connection_aborted()docs while generating your response body so that you can avoid the additional processing if the user aborts before completing the transfer.

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

Sidebar

Related Questions

This question came about because the cells gem specifies template directories using File.join('app','cells'). That
I came across this question on an interview questions thread. Here is the question:
This question came to my head while working with a map in silverlight that
This question came about because code that worked previously in .NET 4.0 failed with
This question came up from what I see on a clients side: Intermittent Connection
This question came to my mind when I learned C++ with a background of
This question came today in the manipulatr mailing list. http://groups.google.com/group/manipulatr/browse_thread/thread/fbab76945f7cba3f I am rephrasing. Given
in my java class we were learning about arrays and this question came up.
What is the difference between above two? This question came to my mind because
Problem This question actually came up at work today. We are planning an experiment

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.