How to troubleshoot the lack of return value of the exec() function in PHP

墨辰丷
Release: 2023-03-27 19:10:01
Original
1694 people have browsed it

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);
Copy after login

can be changed as follows:

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


print_r($output);
Copy after login

Use 2>&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:

Solution to solve the problem of garbled characters after testing with php after connecting to Apache

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!