In PHP, how does one determine that the exec function is successfully executed ?, Php determines the exec Function
Preface
For a code publishing system, PHP'sExec FunctionTo execute commands andGit, svnCommand, how to determine the PHPExec FunctionIs the execution successful?
Solution
Write a PHP file to do the experiment:
Exec FunctionThe first parameter is the command to be executed, the second parameter is the result of execution, and the third parameter is the execution status.
<?phpexec('ls', $log, $status);print_r($log);print_r($status);echo PHP_EOL;
Run the PHP file:
Here$ Log, $ statusOutput result.
However$ Status0. The execution failed, not actually,The exec operation is successful..
Modify the PHP file and give the first exec parameter an incorrect command.
For example:exec(‘lsaa',$log,$status).
Run the command again and run the result.
Here$ StatusThere is indeed a value.
Then prove$ StatusIf the value is 0, exec execution is successful. The PHP official Manual does not explicitly describe this.
The method for executing the command is as follows:
Execute the PHP exec command
Public function runLocalCommand ($ command) {$ command = trim ($ command); $ status = 1; $ log = ''; exec ($ command. '2> & 1', $ log, $ status); // executed command $ this-> command = $ command; // execution status $ this-> status =! $ Status; return $ this-> status ;}
Remove log records and other judgments.
Note:
$this->status = !$status;
The opposite value is returned!
Summary
The above is the judgment in PHPExec FunctionWhether to execute the details of the successful execution and the instance code will help you gain an in-depth understanding of PHP development. I hope this article will help you learn PHP development.