pcntl_fork
Description
The pcntl_fork of PCNTL for PHP forks the currently running process.
Syntax
pcntl_fork(): int
Return
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.
Examples
1 · void
<? $return = pcntl_fork(); echo $return; ?>
2 · parent child
<? $return = pcntl_fork(); if($return == -1) { die("pcntl_fork"); } else if($return) { echo "parent: $return"; pcntl_wait($status);//protect against zombie children } else { echo "child: $return"; } ?>
child: 0
Links
PCNTL
- pcntl_alarm
- pcntl_async_signals
- pcntl_errno
- pcntl_exec
- pcntl_get_last_error
- pcntl_getpriority
- pcntl_rfork
- pcntl_setpriority
- pcntl_signal
- pcntl_signal_dispatch
- pcntl_signal_get_handler
- pcntl_sigprocmask
- pcntl_sigtimedwait
- pcntl_sigwaitinfo
- pcntl_strerror
- pcntl_unshare
- pcntl_wait
- pcntl_waitpid
- pcntl_wexitstatus
- pcntl_wifexited
- pcntl_wifsignaled
- pcntl_wifstopped
- pcntl_wstopsig
- pcntl_wtermsig