PHP » I/O » popen()

Syntax:
int popen(string command, string mode)
command
Command to be executed.
mode
Reading or writing.

Returns a file handle to a process.

Just like fopen(), this function returns a file handle that can be used together with functions like fread() and fwrite(). Instead of a file, the file handle points to a process. The mode parameter specifies whether the file handle should be used for reading or writing to the process. Opening a process for both reading and writing is not supported by popen(). If an error occurs, FALSE is returned.

Examples

Code:
<?php

$ph = popen("cat /etc/services", "r");
for ($i = 0; $i < 5; $i++) {
 print fgets($ph) . "<br>";
}

?>
Output:
# /etc/services:
#
# Network services, Internet style
#
# Note that it is presently the policy of IANA to assign a single well-known
Explanation:

The first five lines of /etc/services are printed.

See Also: