【发布时间】:2017-09-13 02:29:24
【问题描述】:
我在 Heroku 平台上成功部署了我的 php 应用程序。在我的 php 代码中,我通过 shell_exec() 调用 Python 文件,如下所示:
$result = shell_exec('python test.py ' . escapeshellarg($content));
我的 php 应用程序在 localhost 上运行没有问题,我的 php 应用程序的其他功能在 Heroku 上运行。但是当我请求包含此语句的文件时:
$result = shell_exec('python test.py ' . escapeshellarg($content));
python 脚本的输出为空,即 echo $result;是空的。 更清楚地说,如果我在我的本地主机上运行 testpython.php 运行后浏览器中的输出 $result = shell_exec('python test.py ' . escapeshellarg($content));将是:结果:“python 脚本的输出”。但是当我从 Heroku 托管运行 testpython.php 时,结果为空 我通过以下方式检查了主机是否支持 shell_exec 功能:
is_callable('shell_exec') && false === stripos(ini_get('disable_functions'),
'shell_exec');
结果是真的。 testpython.php 只是在 shell 上运行 python 脚本并在浏览器中显示结果。
如果有人知道原因或对此有任何意见/解决方案,很高兴收到他/她的来信。
提示:我认为问题在于我在 python 脚本中使用了一些在 Heroku 服务器上不可用的库。有没有办法在heroku服务器上安装python库(例如nltk)?
【问题讨论】:
-
你的test.py文件和php文件在同一个文件夹吗?
-
您的 PHP 错误日志将包含更多信息
-
@reevkandari 是 test.py 文件与 php 文件位于同一文件夹中
-
是的,正如@iainn 所说的那样。检查日志。并恢复
-
@iainn 我运行,heroku 日志,我发现了这个:“语法错误,意外'$result'(T_VARIABLE),期待',' 或';'在第 16 行的 /app/testpython.php 中“.....但是第 16 行在 localhost 上工作正常。第 16 行:$result = shell_exec('python test.py' .escapeshellarg($content));
标签: php heroku shell-exec