In PHP, the built-in function popen() can open the process file pointer, which is used to open the pipeline to the program specified by the user using the command parameter. The syntax format is "popen(command, mode)", and the parameter mode is specified. Connection mode, the value can be r (read only) or w (write only).
The operating environment of this tutorial: Windows 7 system, PHP version 7.1, DELL G3 computer
popen() is a built-in function in PHP , can open the process file pointer, which is used to open a pipe leading to the program specified by the user using the command parameter.
The popen() function returns a file pointer that is the same as the file pointer returned by fopen(), but it is essentially one-way, that is, it can only be used for reading or writing. The popen() pointer can be used with fgets(), fgetss(), and fwrite(). The file pointer started by popen() function must be closed with pclose().
Syntax:
popen(command,mode)
Parameters | Description |
---|---|
command | Required. Specifies the order to be executed. |
mode | Required. Specifies the connection mode. Possible values:
|
command and mode are sent as parameters To the popen() function, a one-way file pointer is returned on success, and FALSE is returned on failure.
Example:
<?php $file = popen("/bin/ls","r"); //some code to be executed pclose($file); ?>
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to use php popen() function. For more information, please follow other related articles on the PHP Chinese website!