PHP.mk документација

pclose

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.pclose.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.pclose.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
pclose

Референца за `function.pclose.php` со подобрена типографија и навигација.

function.pclose.php

pclose

(PHP 4, PHP 5, PHP 7, PHP 8)

pcloseГо затвора покажувачот на датотеката на процесот

= NULL

pclose(resource $handle): int

Го затвора покажувачот на датотеката на цевката отворена од popen().

Параметри

handle

Показалецот на датотеката мора да биде валиден и мора да биде вратен од успешен повик на popen().

Вратени вредности

Враќа статус на завршување на процесот што бил извршен. Во случај на грешка тогаш -1 се враќа.

Забелешка:

Ако PHP е компајлиран со --enable-sigchild, вратената вредност на оваа функција е недефинирана.

Примери

Пример #1 pclose() example

<?php
$handle
= popen('/bin/ls', 'r');
pclose($handle);
?>

Белешки

Забелешка: Само за Unix:

pclose() внатрешно е имплементиран со користење на waitpid(3) системски повик. За да се добие вистинскиот код за статус на излез pcntl_wexitstatus() функцијата треба да се користи.

Види Исто така

  • popen() - Поставува период на чекање на поток

Белешки од корисници 4 белешки

Uwe Ohse
пред 10 години
Regarding the return value:
"Returns the termination status of the process that was run. In case of an error then -1 is returned. "
and the note about the exit status: "pclose() is internally implemented using the waitpid(3) system call. To obtain the real exit status code the pcntl_wexitstatus() function should be used."

The documentation of the return value is, at best, misleading. The function returns, as does proc_close():
* -1 on error,
* WEXITSTATUS(status) if WIFEXITED(status) is true, or 
* status if WIFEXITED(status) is false,
where status is the status parameter of waitpid().

This makes it impossible to differentiate between a relatively normal exit or a termination by signal, and reduces the value of the proc_close return code to a binary one (ok / something broke).

This can be seen in proc_open_rsrc_dtor() in ext/standard/proc_open.c (PHP 5.4.44, 5.6.12). 

The note advising the use of pcntl_wexitstatus is plain wrong. One cannot use pcntl_wexitstatus because it already has been used.
kcross at nssolutions dot com
пред 22 години
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
пред 23 години
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.
Мајк
пред 17 години
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.
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.