Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

php

What is the pclose() function in PHP?

Muhammad Ashir

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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 the popen() function.

Return value

pclose() returns the termination status of the process that was run. 1-1 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");
?>

RELATED TAGS

php

CONTRIBUTOR

Muhammad Ashir
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring