Hướng dẫn php proc_open
(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8) proc_open — Execute a command and open file pointers for input/output Descriptionproc_open( Parameterscommand The commandline to execute as string. Special characters have to be properly escaped, and proper quoting has to be applied.
As of PHP 7.4.0,
descriptor_spec An indexed array where the key represents the descriptor number and the value represents how PHP will pass that descriptor to the child process. 0 is stdin, 1 is stdout, while 2 is stderr. Each element can be:
The file descriptor numbers are not limited to 0, 1 and 2 - you may specify any valid file descriptor number and it will be passed to the child process. This allows your script to interoperate with other scripts that run as "co-processes". In particular, this is useful for passing passphrases to programs like PGP, GPG and openssl in a more secure manner. It is also useful for reading status information provided by those programs on auxiliary file descriptors. pipes Will be set to an indexed array of file pointers that correspond to PHP's end of any pipes that are created. cwd The initial working dir for the command. This must be an absolute directory path, or env_vars An array with the environment variables for the command that will be run, or options Allows you to specify additional options. Currently supported options include:
Return Values Returns a resource representing the process, which should be freed using proc_close() when you are finished with it. On failure returns Changelog
ExamplesExample #1 A proc_open() example
is_resource($process)) { The above example will output something similar to: Array ( [some_option] => aeiou [PWD] => /tmp [SHLVL] => 1 [_] => /usr/local/bin/php ) command returned 0 Example #2 proc_open() quirk on Windows While one may expect the following program to search the file
filename.txt for the text
The above example will output: 'findstr" "search" "filename.txt' is not recognized as an internal or external command, operable program or batch file. To work around that behavior, it is usually sufficient to enclose the
Notes
See Also
devel at romanr dot info ¶ 10 years ago
simeonl at dbc dot co dot nz ¶ 13 years ago
$read_error != false) mattis at xait dot no ¶ 11 years ago
pcntl_wifexited($status)) { php at keith tyler dot com ¶ 12 years ago
aaronw at catalyst dot net dot nz ¶ 6 years ago
ralf at dreesen[*NO*SPAM*] dot net ¶ 18 years ago
chris AT w3style DOT co.uk ¶ 14 years ago
->_proc = proc_open($command, $descriptorSpec, $pipes); michael dot gross at NOSPAM dot flexlogic dot at ¶ 9 years ago
Kyle Gibson ¶ 17 years ago
Luceo ¶ 12 years ago
mcuadros at gmail dot com ¶ 9 years ago
= array( bilge at boontex dot com ¶ 10 years ago
daniela at itconnect dot net dot au ¶ 19 years ago
andrew dot budd at adsciengineering dot com ¶ 16 years ago
MagicalTux at FF.ST ¶ 18 years ago
Anonymous ¶ 14 years ago
John Wehin ¶ 14 years ago
stoller at leonex dot de ¶ 6 years ago
joachimb at gmail dot com ¶ 14 years ago
Kevin Barr ¶ 16 years ago
stevebaldwin21 at googlemail dot com ¶ 7 years ago
exel at example dot com ¶ 8 years ago
is_file("/tmp/testPipe.gz")) radone at gmail dot com ¶ 14 years ago
preg_match('/decryption failed/i', $error)) {
Matou Havlena - matous at havlena dot net ¶ 12 years ago
addScript($script, $max_execution_time = 300) { weirdall at hotmail dot com ¶ 5 years ago
is_resource($process)) { vanyazin at gmail dot com ¶ 7 years ago
= fsockopen($address, $port);
snowleopard at amused dot NOSPAMPLEASE dot com dot au ¶ 14 years ago
is_executable($GPGPath)) { mendoza at pvv dot ntnu dot no ¶ 16 years ago
picaune at hotmail dot com ¶ 16 years ago
cbn at grenet dot org ¶ 12 years ago
function proc_exec($cmd) jonah at whalehosting dot ca ¶ 14 years ago
jaroslaw at pobox dot sk ¶ 14 years ago
toby at globaloptima dot co dot uk ¶ 10 years ago
|