PHP Tutorial - PHP popen() Function






Definition

The popen() function opens a pipe to the program specified in the command parameter.

Syntax

PHP popen() Function has the following syntax.

popen(command,mode)

Parameter

ParameterIs RequiredDescription
commandRequired.Command to execute
modeRequired.Connection mode.

Possible values for the mode:

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




Return

This function returns FALSE if an error occurs.

Example

Opens a pipe to the program specified in the command parameter


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