触发(多个)curl请求,不要等待响应(PHP) [英] Fire a (multi) curl request and don't wait for the response (PHP)

查看:614
本文介绍了触发(多个)curl请求,不要等待响应(PHP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我有一个聚合器,它在社交媒体网络API上运行搜索,要求他们提供消息.收到响应后,它会触发另一个搜索,以查找较早的消息(分页).这可能会花费相当长的时间,我不想让用户等待此操作完成.

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.

我希望能够从一个主脚本中启动一组PHP脚本,如果您愿意,可以在后台(multi_curl?)进行操作,每个脚本都负责捕获所有这些消息,因此每个脚本都有其网络和要查找的关键字.我希望主脚本仅调用这些其他脚本,然后不等待它们完成,而仅打印出触发的请求,在后台运行"或类似的内容.它将返回JSON,因此必须正确关闭并给出200 OK.

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.

我该怎么做?因此,触发一些multi_curls而不是等待它们完成吗?

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

推荐答案

我不了解您的特定设置,但是您可以创建一个脚本,该脚本使用bash脚本在后台运行PHP脚本,例如这个:

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 &

最后的与号告诉它在后台运行脚本. "nohup"命令告诉它忽略任何挂断信号,以确保即使用户注销该脚本也将继续运行.

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.

这篇关于触发(多个)curl请求,不要等待响应(PHP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆