简体   繁体   English

具有exec功能的PHP脚本无法在浏览器中使用,但是如果我使用“ php5 script_name.php”将其运行到终端中,它将可以使用

[英]Php script with exec function doesn't work into browser but it works if I run it into a terminal with “php5 script_name.php”

my problem: I wrote Php web page that use exec function and it doesn't work into browser but it works if I run it into a terminal with "php5 script_name.php"... where is the problem?!! 我的问题:我写了使用exec函数的PHP网页,但它无法在浏览器中使用,但是如果我将其运行到带有“ php5 script_name.php”的终端中,它将起作用。

Thanks a lot! 非常感谢!

The problem is that the command line PHP can use a different php.ini file. 问题在于命令行PHP可以使用其他php.ini文件。 Try doing phpinfo() and you will see which one each is using. 尝试做phpinfo() ,您将看到每个正在使用的。

The most likely problems are that the current working directory is different and/or the PATH environment variable is different and/or the file permissions are different. 最可能的问题是当前工作目录不同和/或PATH环境变量不同和/或文件许可权不同。 Probably the current working directory (or permissions). 可能是当前的工作目录(或权限)。 Try putting this before your call to exec() : 尝试在调用exec()之前放置它:

chdir($my_directory);

Where $my_directory is the directory from which you're trying to run it in the CLI. 其中$my_directory是您试图在CLI中运行它的目录。

If you're not getting any errors, try putting this at the top of your script: 如果没有任何错误,请尝试将其放在脚本的顶部:

error_reporting(E_ALL);
ini_set('display_errors', 1);

That might give you a better idea of the problem. 这可能会使您对问题有更好的了解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM