Command Format


The format of the system() function is as follows:

string system(string $command_string[, string arg1, string arg2, ...]);

The system function returns a string after operation.

Format 1: only a command string without parameter

The followings are the examples which have a command string without any parameter.

<?php
system("php main.php");  // Run main.php
?>
<?php
system("php -d 3 main.php");  // Run main.php (restart delay: 3 seconds)
?>
<?php
// Run main.php (CPU time: 500us, restart delay: 3 seconds)
system("php -t 500 -d 3 main.php");
?>

Format 2: command with parameter(s)

The words starting with '%' followed by a number in the command string are replaced by parameters. This format is useful when a command includes any space or control character. The followings are the examples which have a command string with parameters.

<?php
$script = "main.php";
system("php %1",$script);  // Run main.php
?>
<?php
$delay = "3";
$script = "main.php";
system("php -d %1 %2", $delay, $script);  // Run main.php (restart delay: 3 seconds)
?>
<?php
$php_id = "0";
$cpu_time = "500";
$delay = "3";
$script = "main.php";
// Run main.php (CPU time: 500us, restart delay: 3 seconds)
system("php -t %2 -d %3 %4", $php_id, $cpu_time, $delay, $script);
?>