pcntl_waitpid

FunctionParams and return types changed in PHP 8.0

Waits on or returns the status of a forked child.

PHP 5
PHP 7.0
Improved
PHP 7.1-7.4
PHP 8.0
Improved
PHP 8.1
PHP 8.2-8.3
PHP 8.4
PHP 8.5
PHP 8.6

pcntl_waitpid Function synopsis

pcntl_waitpid(
    int $process_id,
    &$status,
    int $flags = 0,
    &$resource_usage = []
  ): int

Parameters

$process_id

Typeint

The value of $process_id can be one of the following:

$status

Passed by reference

pcntl_waitpid will store status information in the $status parameter which can be evaluated using the following functions: pcntl_wifexited, pcntl_wifstopped, pcntl_wifsignaled, pcntl_wexitstatus, pcntl_wtermsig and pcntl_wstopsig.

$flags

OptionalTypeintDefault value0

The value of $flags is the value of zero or more of the following two global constants OR'ed together:

$resource_usage

Passed by reference, OptionalDefault value[]

Note that the parameters $status and $resource_usage are passed by reference, and contain additional/updated context data that may be useful.

Return value

Typeint

pcntl_waitpid returns the process ID of the child which exited, -1 on error or zero if WNOHANG was used and no child was available

Changes to the pcntl_waitpid Function

PHP 8.0

  • Return type added: int
  • Parameter name of parameter #1 changed: $pid to $process_id
  • Parameter type added for parameter #1 ($process_id): int
  • Parameter name of parameter #3 changed: $options to $flags
  • Parameter type added for parameter #3 ($flags): int
  • Parameter default value added for position #3 ($flags): 0
  • Parameter name of parameter #4 changed: $rusage to $resource_usage
  • Parameter default value added for position #4 ($resource_usage): []
  pcntl_waitpid(
-     $pid,
+     int $process_id,
      &$status,
-     $options,
+     int $flags = 0,
-     &$rusage
+     &$resource_usage = []
-   )
+   ): int

PHP 7.0

  • Optional parameter added - #4: &$rusage
 pcntl_waitpid(
     $pid,
     &$status,
-    $options
+    $options,
+    &$rusage
   )

pcntl_waitpid Function Availability

PHP VersionAvailability
PHP 8.6Upcoming Release Yes
PHP 8.5Supported (Latest) Yes
PHP 8.4Supported Yes
PHP 8.3Security-Fixes Only Yes
PHP 8.2Security-Fixes Only Yes
PHP 8.1Unsupported Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported Yes
PHP 5.3Unsupported Yes