To do a code release system, you need to use the EXEC function of PHP to execute Linux commands and GIT,SVN commands, how to determine whether the EXEC function of PHP is executed successfully?
Write a php file to do the experiment:
exec function parsing
EXEC syntax: string exec (String command, string [array], int [return_var]);
EXEC return Value: string
EXEC parameter description
command– the command to be executed
array– is the output value
return_var– is the return value of 0 or 1, and if 0 is returned, the execution succeeds, and the return 1 fails.
The first parameter of the EXEC function is the command executed, the second parameter is the result of execution, and the third is the state of execution.
<?php
EXEC (' ls ', $log, $status);
Print_r ($log);
Print_r ($status);
Echo Php_eol;
Execute this PHP file:
Here $log, $status output as shown.
But $status is 0, giving people the feeling that execution failed, in fact not, that exec executed successfully.
Change this php file and give exec the first argument with a wrong command.
such as: exec (' LSAA ', $log, $status).
Execute again, run the results as shown in figure:
There is a value in $status here.
Then proving that $status is 0 indicates that exec execution was successful. This is not explicitly stated in the official PHP manual.
The final way to execute the command is as follows:
PHP exec Execute command PHP
Public Function Runlocalcommand ($command) {
$command = Trim ($command);
$status = 1;
$log = ';
EXEC ($command. ' 2>&1 ', $log, $status);
Commands that have been executed
$this->command = $command;
Status of execution
$this->status =! $status;
return $this->status;
}
Eliminates log records and other judgments.
Note here:
$this->status =! $status;
Return to the state of the time to take the opposite value!