php-pcntlHow to use pcntl_wait in PHP?
PCNTL_WAIT is a PHP function used to wait for a child process to finish executing. It is part of the Process Control (PCNTL) extension.
Example
<?php
$pid = pcntl_fork();
if ($pid == -1) {
die('could not fork');
} else if ($pid) {
// parent process
pcntl_wait($status); //Protect against Zombie children
} else {
// child process
// do some work
exit();
}
?>
The code above will create a child process and wait for it to finish executing before continuing.
Code explanation
- pcntl_fork(): Creates a child process
- pcntl_wait($status): Waits for the child process to finish executing
- exit(): Exits the child process
Helpful links
More of Php Pcntl
- How to use PCNTL alarm in PHP?
- How to use pcntl_wifexited in PHP?
- How to use pcntl_signal in PHP?
- How to use pcntl_waitpid in PHP?
- How to get the process ID with PHP PCNTL?
- How to prevent zombie processes with the PCNTL_FORK function in PHP?
- How to use pcntl_wexitstatus in PHP?
- How to install PCNTL for PHP in Debian?
- How to check if PCNTL is enabled in PHP?
See more codes...