通过进程 ID 终止正在运行的 PHP 脚本?

发布于 2024-08-13 21:20:55 字数 152 浏览 8 评论 0原文

我通过 AJAX 向多个 PHP 脚本发出大量 GET 请求。我想请求有关如何终止当前正在运行(在后台)的 PHP 脚本的实施建议。

有没有什么方法可以在运行时获取 PHP 脚本进程 ID,然后我可以通过 shell/cmd 等杀死该进程?

有更好的办法吗?

I make lots of GET requests to several PHP scripts via AJAX. I want to ask for implementation advice on how to kill a PHP script that is currently running (in the background).

Is there some way to get the PHP scripts process ID when it runs and then I can probably kill that process via shell/cmd etc?

Is there a better way?

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

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

发布评论

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

评论(2

毁虫ゝ 2024-08-20 21:20:55

PHP 是否是一个独立的进程取决于 PHP 和 Web 服务器的配置方式。但即使是这样,要捕获正确的 PHP 进程并杀死它也将非常困难。

如果您在 PHP 脚本中知道这是需要终止的进程,您可以使用 getmypid() 或在用户贡献的注释中找到一些内容。

我仍然不完全了解情况。为什么你需要杀死他们?

Whether PHP is a process of its own at all will depend on how PHP and web server are configured. But even when it is, it is going to be awfully hard to catch the correct PHP process to kill.

If you know inside your PHP script that this is the process that needs killing, you may be able to use getmypid() or find something in the User Contributed Notes there.

I still don't entirely understand the situation. Why do you need to kill them at all?

╰つ倒转 2024-08-20 21:20:55

我没有完全明白你想要做什么,但我认为你可能已经到达了网络堆栈的一部分,这是一个死胡同。如果您发出大量 ajax 请求,您肯定会杀死您的服务器,因为它无法处理“无限”数量的连接。

我认为你可能需要重新考虑你的架构。您可能想阅读 COMET长轮询

I did not exactly get, what you are trying to do, but I think you might have reached a part of the web stack that is a dead end. If you are making a lot of ajax requests, you will definitely kill your server, because it cannot handle an "infinite" amount of connections.

I think you might have to rethink your architecture. You might want to read into COMET and long polling.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文