proc_close()

proc_close() — Close pipes to a process opened by proc_open(), wait for it to terminate, and return its exit code.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

What it does

proc_close() is similar to pclose() except that it only works on processes opened by proc_open(). proc_close() waits for the process to terminate, and returns its exit code. Open pipes to that process are closed when this function is called, in order to avoid a deadlock - the child process may not be able to exit while the pipes are open.

Signature

proc_close(resource $process): int

Parameters

ParameterTypeWhat it takes
$processresourceThe proc_open() resource that will be closed.

Return value

Returns the termination status of the process that was run. In case of an error, -1 is returned. Note: If PHP has been compiled with --enable-sigchild, the return value of this function is undefined. If PHP has been compiled with --enable-sigchild, the return value of this function is undefined.

Example

The PHP manual ships no example for proc_close(); the signature and the parameter table above are the contract.

Changelog

VersionChange
8.3.0proc_close() now returns the correct exit code even after proc_get_status() was called first. Previously, -1 was returned in that case.

All PHP 8.5 built-in functions

Reference card built from the PHP manual page proc_close() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.