PHP 调用服务器脚本 - 调用后不会继续

发布于 2025-01-07 02:36:30 字数 788 浏览 5 评论 0原文

是的,我正在 PHP 脚本中调用 Python 脚本。该 PHP 脚本需要在调用 Python 脚本后继续。

我已经尝试了以下所有方法,但 PHP 坚持等待脚本响应。

全部尝试过:-

system('nohup python /home/process/script.py -i '.escapeshellarg($location).' &');
system('nohup python /home/process/script.py -i '.escapeshellarg($location).' 2>&1 &');
system('nohup python /home/process/script.py -i '.escapeshellarg($location).' < /dev/null 2>&1 &');
exec('nohup python /home/process/script.py -i '.escapeshellarg($location).' &');
exec('nohup python /home/process/script.py -i '.escapeshellarg($location).' 2>&1 &');
exec('nohup python /home/process/script.py -i '.escapeshellarg($location).' < /dev/null 2>&1 &');

还尝试过使用 passthru 且不使用 nohup。

非常感谢任何帮助。

Right, I am calling a Python script in a PHP script. This PHP script needs to continue after the Python script has been called.

I have tried all of the following, yet PHP insists on waiting until the script has responded.

All tried:-

system('nohup python /home/process/script.py -i '.escapeshellarg($location).' &');
system('nohup python /home/process/script.py -i '.escapeshellarg($location).' 2>&1 &');
system('nohup python /home/process/script.py -i '.escapeshellarg($location).' < /dev/null 2>&1 &');
exec('nohup python /home/process/script.py -i '.escapeshellarg($location).' &');
exec('nohup python /home/process/script.py -i '.escapeshellarg($location).' 2>&1 &');
exec('nohup python /home/process/script.py -i '.escapeshellarg($location).' < /dev/null 2>&1 &');

Also tried with passthru and without nohup.

Any help greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫九 2025-01-14 02:36:30

引用 exec 文档

如果程序使用此函数启动,为了使其继续在后台运行,程序的输出必须重定向到文件或另一个输出流。如果不这样做将导致 PHP 挂起,直到程序执行结束。

你应该尝试这个:

exec('nohup python /home/process/script.py -i '.escapeshellarg($location).' &>/dev/null &');

Quoting the exec doc:

If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do so will cause PHP to hang until the execution of the program ends.

You should try this instead:

exec('nohup python /home/process/script.py -i '.escapeshellarg($location).' &>/dev/null &');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文