触发(多)curl 请求并且不等待响应(PHP)

发布于 2024-11-27 18:40:16 字数 369 浏览 3 评论 0原文

我想触发一组 PHP 脚本(通过 multi_curl),而不是等待调用者脚本的响应(200 OK):

我有一个聚合器,它在社交媒体网络 API 上运行搜索,要求它们提供消息。当它收到响应时,它会启动另一次搜索较早的消息(寻呼)。这可能需要相当长的时间,我不想让用户等待它完成。

我希望能够从一个主脚本启动一组 PHP 脚本,如果你愿意的话,在后台(multi_curl?),每个脚本都会负责抓取所有这些消息,每个脚本都有自己的网络和关键字观望。我希望主脚本只调用这些其他脚本,然后不等待它们完成,只打印出“请求已触发,在后台运行”或类似的内容。它将返回 JSON,因此它必须正确关闭并给出 200 OK。

我该怎么做?那么启动一些 multi_curls 而不等待它们完成?

I want to fire a set of PHP script (through multi_curl) and not wait for a response from the caller script (200 OK):

I have an aggregator that runs searches on social media network APIs asking them for messages. When it gets a response it fires up another search for messages that were earlier (paging). This can take quite a long time and I don't want to make users wait for this to finish.

I would like to be able to fire up a set of PHP scripts from one main script, if you will, in the background (multi_curl?) that will each take care of grabbing all these messages, each script will have its network and keyword to look on and for. I want the main script to just call these other scripts and then not wait for them to finish and just print out 'requests fired, running in background' or something of the sort. It will return JSON, so it would have to properly close and give 200 OK.

How can I do this? So fire some multi_curls and not wait for them to finish?

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

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

发布评论

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

评论(2

悲凉≈ 2024-12-04 18:40:17

看一下 Ruby 的delayed_job 的PHP 端口。

https://github.com/seatgeek/djjob

Have a look at the PHP port of Ruby's delayed_job.

https://github.com/seatgeek/djjob

知你几分 2024-12-04 18:40:17

我不了解您的特定设置,但您也许可以创建一个脚本,使用如下所示的 bash 脚本在后台运行 PHP 脚本:

nohup php /path/to/script.1.php &
nohup php /path/to/script.2.php &
nohup php /path/to/script.3.php &

末尾的 & 告诉它在后台运行脚本。 “nohup”命令告诉它忽略任何挂断信号,确保即使用户注销脚本也将继续运行。

I'm not privy to your particular setup, but you might be able to create a single script that runs your PHP scripts in the background with a bash script like this:

nohup php /path/to/script.1.php &
nohup php /path/to/script.2.php &
nohup php /path/to/script.3.php &

The ampersand at the end tells it to run the script in the background. the "nohup" command tells it to ignore any hangup signal, ensuring the script will continue running even if the user logs out.

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