What is the pclose() function in PHP?
pclose() closes a pipe opened by the popen() function. The file pointer initiated by the popen() function must be closed with pclose().
Syntax
pclose(resource $handle): int
Parameters
handle: The file pointer returned by the call to thepopen()function.
Return value
pclose() returns the termination status of the process that was run. is returned in case of an error.
Code
The following code demonstrates the use of pclose(). Here, the termination status returned from the call to pclose() is stored in $exit_status and printed out to the standard output.
<?php$handle = popen('/bin/ls', 'r');$read = fread($handle, 2048);$exit_status = pclose($handle);print_r("Exit Status: $exit_status\n");?>
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved