PHP Velho Oeste 2024


(PHP 8 >= 8.1.0)

pcntl_rforkManipulates process resources


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

Manipulates process resources.



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.


The signal number.

Return Values

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.


Example #1 pcntl_rfork() example


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

The above example will output something similar to:




This function is only available on BSD systems.

See Also

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top