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 8169869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:59:06+00:00 2026-06-06T20:59:06+00:00

I have 2 PHP files. One file is caller.php and the other is worker.php

  • 0

I have 2 PHP files. One file is caller.php and the other is worker.php

caller.php will start worker.php on the (linux) system and caller.php should be ended immediately (while worker.php is still working on the server)

The worker.php is taking a lot of time and it will write the status to a database or a file.

I want to be able to open caller.php in the browser which starts ‘php worker.php’, close the browser, come back in 5 minutes and check the status.. (or the script will send a mail after completion) – any ideas how to do this?

  • 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-06T20:59:08+00:00Added an answer on June 6, 2026 at 8:59 pm

    You can end client connection and still continue processing, all done. You may also want to increase php timeout if processing takes more time than php/httpd global config allows. See set_time_limit();.

    This is not exactly what you asked but I think it may be X/Y problem so here we use technique that can be used to:

    • Display Processing started page to user.
    • close user connection.
    • start longer processing.

    So basically this answers to your described needs instead of "how to do X?".

    Caller

    // Ignore user abort and set Connection close header
    ignore_user_abort(true);
    header("Connection: close");
    
    // Start controlled buffering
    ob_start();
    echo "<h1>Processing started, come back tomorrow to see results</h1>";
    
    // Get buffer length and manually add it to headers.
    $size = ob_get_length();
    header("Content-Length: $size");
    
    // Flush buffers, user sees "Processing started" message.
    ob_end_flush();
    flush();
    
    // At this point connection to client should be closed already.
    // Here we start our worker, there is no need to do fork() or 
    // anything like that. Client browser is not listening anymore.
    // All we need to do is simply start working and start writing
    // status logs to somewhere so that client can retrieve status
    // with another request, let's say from checkworkerstatus.php
    include "worker.php";
    $worker = new worker();
    $worker->start_long_processing();
    

    Not forking or killing caller to leave worker running alone?

    That’s right, and that’s because there’s no need to.

    Yes, you asked for behavior where "caller.php will start worker.php on the (linux) system and caller.php should be ended immediately (while worker.php is still working on the server)". However, there is no need to do it that way if you don’t want to do multithreading-singleuser app with php. Just let users 1. start something, 2. leave it running, 3. disconnect users, 4. go back to start where users can start more something or quit if bored enough already.

    Of course you can replace everything after flush(); with anything, difference is that clients does not anymore listen so that all output goes to black hole named /dev/null. For example test it with something like this:

    ...end_flush();
    flush();
    
    // At this point connection to client should be closed already.
    echo "Nobody sees this message";
    while(rand(0,10) != 1) {
        echo "Nobody sees this message";
        error_log(date("mdyHis")." Still running...");
        sleep(10);
    }
    ...
    

    See http://php.net/features.connection-handling for more information.
    Also read http://php.net/function.flush if there seems to be any problems with flushing buffer and closing user connection.
    There is also another question (with answers) about Why does PHP not support multithreading?

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

Sidebar

Related Questions

Iam making an app which has one index.php file. I also have these other
I have several PHP files include()ing other files from several other directories. In one
i have one php file which process adding of record in Database fro array.
I have a PHP file with one simple echo function: echo 'アクセスは撥ねりません。'; but when
I have problem with session in cakephp.I have one file chat.php that is in
I have a php file setup to pull through ONE XML data feed, What
I have one line in php file like this: <a class=hide-if-no-js onclick=findPosts.open( 'media[]','<?php echo
I have three files: one called sql.php witch has a class db that I
I have three files in a folder 'test' one.php two.php print.html And i have
My OS environment is linux. I have a php file in this folder -

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.