Home >Backend Development >PHP Tutorial >Briefly introduce the troubleshooting method for PHP's exec() function without return value (recommended)

Briefly introduce the troubleshooting method for PHP's exec() function without return value (recommended)

黄舟
黄舟Original
2017-04-01 09:13:261636browse

The following editor will bring you a brief discussion of PHP's exec()functionNo return value troubleshooting method (must read). The editor thinks it’s pretty good, so I’ll share it with you now and give it as a reference. Let’s follow the editor and take a look.

In securityimagemagic, exec needs to be used on many serversInstallationfailed

exec() executes externally The command failed without any error message.

exec executes a certain command without any problem on the command line, but an error occurs in php. This problem is 99.99% related to permissions, but the command executed by exec will not return an error. One trick is to use pipe commands, assuming your exec call is as follows:

exec('convert a.jpg b.jpg', $output, $return_val);

can be changed as follows:

exec('convert a.jpg b.jpg 2>&1', $output, $return_val); 


print_r($output);

Use 2>&1, the command will output the error during shell execution to the $output variable, and output the variable for analysis.

Remarks: exec has 3 parameters. The first one is the command to be executed. The second parameter is an array. The value of the array is generated after the first command is executed. , The status of the third parameter execution, 0 indicates success, and the others indicate failure.

There are three functions in php that can be used to execute external commands system, exec, and passthru.

The above is the detailed content of Briefly introduce the troubleshooting method for PHP's exec() function without return value (recommended). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn