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

查看:34
本文介绍了触发(多)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天全站免登陆