未能在 Heroku 平台(托管)上从 PHP 调用 Python 脚本
failed to call a Python Script from PHP on Heroku platform(hosting)
我在 Heroku 平台上成功部署了我的 php 应用程序。在我的 php 代码中,我通过 shell_exec() 调用 Python 文件,如下所示:
$result = shell_exec('python test.py ' . escapeshellarg($content));
我的 php 应用程序在本地主机上运行,没有问题,我的 php 应用程序的其他功能在 Heroku 上运行。但是当我请求包含此语句的文件时:
$result = shell_exec('python test.py ' . escapeshellarg($content));
python 脚本的输出为空,即 echo $result;是空的。
更清楚地说,如果我 运行 testpython.php 在我的本地主机上 运行 $result = shell_exec('python test.py ' . escape[=46= 之后浏览器中的输出]arg($内容));将是:结果:"the output here from python script"。但是当我 运行 testpython.php 来自 Heroku 托管时,结果为空
我通过 :
检查主机是否支持 shell_exec 功能
is_callable('shell_exec') && false === stripos(ini_get('disable_functions'),
'shell_exec');
结果是真的。
testpython.php 只是 运行 shell 上的 python 脚本并在浏览器中显示结果。
如果有人知道原因或对此有任何 comment/solution,很高兴收到 him/her 的来信。
提示:我认为问题是我在 python 脚本中使用了一些在 Heroku 服务器上不可用的库。有没有办法在 heroku 服务器上安装 python 库(例如 nltk)?
我猜问题是我在 python 脚本中使用了一些在 Heroku 服务器上不可用的库。因为我的应用程序是 PHP,所以默认的构建包是 PHP。最后,我使用了多个 Buildpacks(一个用于 PHP,另一个用于 python)来解决 heroku 服务器上所有不可用的库。现在我的应用程序完美运行并且 php 脚本调用远程 python 脚本
我在 Heroku 平台上成功部署了我的 php 应用程序。在我的 php 代码中,我通过 shell_exec() 调用 Python 文件,如下所示:
$result = shell_exec('python test.py ' . escapeshellarg($content));
我的 php 应用程序在本地主机上运行,没有问题,我的 php 应用程序的其他功能在 Heroku 上运行。但是当我请求包含此语句的文件时:
$result = shell_exec('python test.py ' . escapeshellarg($content));
python 脚本的输出为空,即 echo $result;是空的。 更清楚地说,如果我 运行 testpython.php 在我的本地主机上 运行 $result = shell_exec('python test.py ' . escape[=46= 之后浏览器中的输出]arg($内容));将是:结果:"the output here from python script"。但是当我 运行 testpython.php 来自 Heroku 托管时,结果为空 我通过 :
检查主机是否支持 shell_exec 功能is_callable('shell_exec') && false === stripos(ini_get('disable_functions'),
'shell_exec');
结果是真的。 testpython.php 只是 运行 shell 上的 python 脚本并在浏览器中显示结果。
如果有人知道原因或对此有任何 comment/solution,很高兴收到 him/her 的来信。
提示:我认为问题是我在 python 脚本中使用了一些在 Heroku 服务器上不可用的库。有没有办法在 heroku 服务器上安装 python 库(例如 nltk)?
我猜问题是我在 python 脚本中使用了一些在 Heroku 服务器上不可用的库。因为我的应用程序是 PHP,所以默认的构建包是 PHP。最后,我使用了多个 Buildpacks(一个用于 PHP,另一个用于 python)来解决 heroku 服务器上所有不可用的库。现在我的应用程序完美运行并且 php 脚本调用远程 python 脚本