略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: pcntl_rfork

2024-12-22

pcntl_rfork

(PHP 8 >= 8.1.0)

pcntl_rforkManipulates process resources

说明

pcntl_rfork(int $flags, int $signal = 0): int

Manipulates process resources.

参数

flags

The flags parameter determines which resources of the invoking process (parent) are shared by the new process (child) or initialized to their default values.

flags is the logical OR of some subset of:

  • RFPROC: If set a new process is created; otherwise changes affect the current process.
  • RFNOWAIT: If set, the child process will be dissociated from the parent. Upon exit the child will not leave a status for the parent to collect.
  • RFFDG: If set, the invoker's file descriptor table is copied; otherwise the two processes share a single table.
  • RFCFDG: If set, the new process starts with a clean file descriptor table. Is mutually exclusive with RFFDG.
  • RFLINUXTHPN: If set, the kernel will return SIGUSR1 instead of SIGCHILD upon thread exit for the child. This is intended to do Linux clone exit parent notification.
signal

The signal number.

返回值

On success, the PID of the child process is returned in the parent's thread of execution, and a 0 is returned in the child's thread of execution. On failure, a -1 will be returned in the parent's context, no child process will be created, and a PHP error is raised.

范例

示例 #1 pcntl_rfork() example

<?php

$pid 
pcntl_rfork(RFNOWAIT|RFTSIGZMBSIGUSR1);
if (
$pid 0) {
  
// This is the parent process.
  
var_dump($pid);
} else {
  
// This is the child process.
  
var_dump($pid);
  
sleep(2); // as the child does not wait, so we see its "pid"
}
?>

以上例程的输出类似于:

int(77093)
int(0)

参见

  • pcntl_fork() - 在当前进程当前位置产生分支(子进程)。译注:fork是创建了一个子进程,父进程和子进程 都从fork的位置开始向下继续执行,不同的是父进程执行过程中,得到的fork返回值为子进程 号,而子进程得到的是0。
  • pcntl_waitpid() - 等待或返回fork的子进程状态
  • pcntl_signal() - 安装一个信号处理器
  • cli_set_process_title() - Sets the process title
add a noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/function.pcntl-rfork.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3