Write daemon with PHP that cannot reside

Source: Internet
Author: User
For example, a file like the following test.php


  
    /dev/null 2>&1 & echo $!");?>

Execute PHP test.php under terminal to leave the process in the background
However, when accessing test.php through a browser, you cannot leave a process in the background

Speculation may be the Web process aborted at the same time sleep also to abort, want to keep, what good solution?

Reply content:

For example, a file like the following test.php


  
    /dev/null 2>&1 & echo $!");?>

Execute PHP test.php under terminal to leave the process in the background
However, when accessing test.php through a browser, you cannot leave a process in the background

Speculation may be the Web process aborted at the same time sleep also to abort, want to keep, what good solution?

Use the swoole extension to write a PHP socket server that runs as a daemon.

Try PHP for this function Ignore_user_abort specific usage reference http://cn2.php.net/manual/en/function.ignore-user-abort.php

It should all be here:
http://www.php.net/manual/en/features.connection-handling.php

Basically:

    1. By default, the script aborts if the remote client disconnects. Change the default setting by Ignore_user_abort (php.ini), Ignore_user_abort (Apache httpd.conf), or by calling the Ignore_user_abort () function;

    2. The default script has a maximum run time of 30 seconds. Can be modified by Max_execution_time (php.ini), Max_execution_time (Apache httpd.conf) or by calling the Set_time_limit () function.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.