(PHP 4, PHP 5, PHP 7)

pcloseSchließt einen Prozess-Dateizeiger


int pclose ( resource $handle )

Schließt einen Prozess-Dateizeiger, der durch einen Aufruf von popen() geöffnet wurde.



Der Dateizeiger muss gültig und durch einen erfolgreichen Funktionsaufruf von popen() zurückgegeben worden sein.


Gibt den End-Status des ausgeführten Prozesses zurück. Im Fehlerfall wird -1 zurückgegeben.


Beispiel #1 pclose() Beispiel



Hinweis: Nur unter Unix:

pclose() ist intern unter Verwendung des waitpid(3) Systemaufrufs implementiert. Um den wirklichen Exit-Statuscode zu erhalten, sollte die Funktion pcntl_wexitstatus() verwendet werden.

Siehe auch

  • popen() - Öffnet einen Prozesszeiger

add a note add a note

User Contributed Notes 3 notes

7 years ago
The termination status, as pointed out in another note, is not the same as the exit status from the process. However, something like "pclose($fp)/256" is not the correct way to extract the exit status, since this uses system- and version-specific knowledge of where in the termination status the exit status is stored. (Also, the process may not even have exited normally, so it may not have an exit status at all.)

Instead, the functions pcntl_wifexited() and pcntl_wexitstatus() should be used. They are wrappers for the C macros WIFEXITED() and WEXITSTATUS() that are designed for determining whether the process had an exit status and what that status was, respectively.
kcross at nssolutions dot com
12 years ago
Somewhere between 4.1.1 and 4.2.3, the return value from pclose changed.

The exit status used to be in the second byte, so that the status would be (pclose($fp)/256).

It is now in the low-order byte, so the status is just pclose($fp).

Be careful.
vdweij at mailsurf dot com
12 years ago
As I understand pclose will return 0 (on every platform) in case popen could not execute the specified command.

Since popen only returns the status wether it was able to send a command and not wether it was succesfully executed. Only the returned value of pclose can be used to check wether a command could be executed.
To Top