PHP exec() 无法正常工作 [英] PHP exec() not working properly

查看:30
本文介绍了PHP exec() 无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 PHP exec() 函数时遇到困难.它似乎没有调用某些函数.例如,代码 echo exec('ls'); 不会产生任何输出(应该,目录中有文件).这对我来说是个问题的主要原因是我正在尝试从 PHP exec() 调用中执行 .jar.

I am having difficulty with the PHP exec() function. It seems to not be calling certain functions. For instance, the code echo exec('ls'); produces no output whatsoever (it should, there are files in the directory). That main reason this is a problem for me is that I'm trying execute a .jar from a PHP exec() call.

据我所知,我正在正确调用 java 程序,但没有得到任何输出..jar 可以从服务器上的命令行执行.(为了记录,它是一个 apache 服务器).

As far as I know I'm calling the java program properly, but I'm not getting any of the output. The .jar can be executed from the command line on the server. (For the record, it's an apache server).

我的 .jar 执行的 php 如下所示:

My php for the .jar execute looks like this:

$output = array();
exec('java -jar testJava.jar', $output);
print_r($output);

我从这个 exec() 调用中得到的输出是 Array().

All I get for output from this exec() call is Array().

我已经成功使用 exec() 执行 'whoami''pwd'.我不明白为什么有些功能可以工作,有些则不行.我也不是最有经验的 PHP 人,所以我不太确定如何诊断问题.任何和所有帮助将不胜感激.

I have had success with exec() executing 'whoami' and 'pwd'. I can't figure out why some functions are working and some aren't. I'm not the most experienced person with PHP either, so I'm not too sure how to diagnose the issue. Any and all help would be appreciated.

推荐答案

我发现了问题 - SELinux 阻止 PHP 访问某些功能.将 SELinux 置于许可模式已解决了这些问题(尽管我不想让 SELinux 处于许可模式;如果可以,我宁愿找到一种允许某些功能的方法).

I have found the issue - SELinux was blocking PHP from accessing certain functions. Putting SELinux into permissive mode has fixed the issues (although, I'd rather not have to leave SELinux in permissive mode; I'd rather find a way of allowing certain functions if I can).

这篇关于PHP exec() 无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆