How to solve the problem of php exec error reporting
Today, I will introduce to you how to solve the problem of php exec error reporting. The content of the article is good. Now I would like to share it with you. Friends who feel in need can understand it. I hope it will be helpful to you. Let's read it along with the editor's ideas.
Php exec error solution: 1, modify the ping or the corresponding command execution permissions; 2, the command full path completion "exec ('/ usr/sbin',$output);"; 3, add the target directory in the environment variable.
This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer
How to solve the problem of php exec error reporting?
The exec () function in PHP failed to execute the system command. 0. Description
In php, we can use exec () to execute system commands, but sometimes we encounter situations where the execution of the exec () command is unsuccessful or there is no return, so let's explain this:
1. Function exec (string $command [, array & $output [, int & $return_var]]): string parameter description: the command to be executed by 1.$command 2.$output execution result 3.$return_var if both $output and this variable are set, the return status of the command execution will be written to this variable 2. Example exec ("ping www.baidu.com", $output)
Normally, the execution result is no different from executing ping directly on the server, but it can lead to unexpected conditions due to some reasons. Here are two explanations and solutions.
2.1 permission issues
problem
When we execute the linux system command directly on the server (in this case, ping), the execution permission depends on the permission of our login user. If the login user is root, we use root to execute ping. But when we visit the website, our user at this time is www, if we do not modify the execution permissions of ping, it will not be able to execute successfully.
Solve
Modify the execution permission of ping or corresponding command 2.2 Command path problem
problem
In another case, when we execute a command with exec, we do not report an error or return a result, because the command is not in the directory where the environment variable is configured, that is, in the / etc/profile file. Taking ifconfig as an example, we can use whereis ifconfig to find out the specific path of the command, such as the path under / usr/sbin. There are two solutions:
Solve
1 copy the command to / usr/bin, that is, the directory under the environment variable (not recommended)
2 directly complete the full path of the command exec ('/ usr/sbin',$output); (recommended)
3 adding the target directory in the environment variables such as adding / usr/sbin to the directory is all the contents of how to solve the php exec error problem, more content related to how to solve the php exec error problem can search the previous article or browse the following article to learn ha! I believe the editor will add more knowledge to you. I hope you can support it!