PHP uses the process as the Daemon. php daemon _ PHP Tutorial

Source: Internet
Author: User
PHP uses the process as the Daemon, and the php process daemon. PHP uses the process as the Daemon. The php process daemon describes how PHP uses the process as the daemon. Share it with you for your reference. The specific analysis is as follows: PHP uses the process as the Daemon, and php process daemon

This example describes how PHP uses a process as a daemon. Share it with you for your reference. The specific analysis is as follows:

Usage of posix_setsid () in php

The document explains "Make the current process a session leader"

Reference: http://linux.die.net/man/2/setsid

This means that the process that calls this function between a process Group (parent process and child process) will be elected as the leader of the process Group.

So the way to make a process a daemon is:

1 fork generates a sub-process

2 in the sub-process posix_setsid ()

3. exit the parent process.

This document provides an example:

<?php  $pid = pcntl_fork(); // fork  if ($pid < 0)    exit;  else if ($pid) // parent    exit;  else { // child    $sid = posix_setsid();    if ($sid < 0)      exit;    for($i = 0; $i <= 60; $i++) {//do something for 5 minutes      sleep(5);    }  }?>

I hope this article will help you with php programming.

In this example, PHP uses the process as the daemon. Share it with you for your reference. The specific analysis is as follows :...

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.