PHP popen() Function

Definition and Usage

The popen() function opens a process file pointer.

Syntax

popen(command,mode)
Parameter Description
command Required. Specifies the command to be executed.
mode

Required. Specifies the connection mode.

Possible values:

  • r: Read only.
  • w: Write only (opens and clears an existing file or creates a new file)

Description

Opens a pipe to a process specified by spawning command command execution.

that is generated by fopen() with the same file pointer returned by pclose() to close. This pointer can be used fgets(),fgetss() and fwrite().

Returns false if an error occurs.

Example

<?php
$file = popen("/bin/ls","r");
//Some code to be executed
pclose($file);
?>