Home>Article>Backend Development> How to troubleshoot the lack of return value of the exec() function in PHP
This article mainly introduces the method of troubleshooting the exec() function in PHP without a return value. Interested friends can refer to it. I hope it will be helpful to everyone.
In order to secure imagemagic, exec needs to be used. The installation failed on many servers.
exec() failed to execute external commands, but there was no 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);
Use2>&1, the command will output the error during shell execution to the $output variable, output This variable is ready 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 execution status of the third parameter, 0 indicates success, 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 entire content of this article, I hope it will be helpful to everyone's study.
Related recommendations:
PHPExample of using Curl to simulate login and capture data
php uses cookies to realize the function of remembering user names and passwords on web pages
The above is the detailed content of How to troubleshoot the lack of return value of the exec() function in PHP. For more information, please follow other related articles on the PHP Chinese website!