PHP并发HTTP请求? [英] PHP Concurrent HTTP requests?

查看:349
本文介绍了PHP并发HTTP请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在PHP中进行并发HTTP请求的最佳方法是什么?我有很多数据可以获取,我宁愿一次做多个请求来检索所有数据。

I was wondering what the best way to do concurrent HTTP requests in PHP? I have a lot of data to get and i'd rather do multiple requests at once to retrieve it all.

有人知道我该怎么做吗?最好是匿名/回调函数mannor ...

Does anybody know how I can do this? Preferably in an anonymous/callback function mannor...

谢谢,

汤姆。

推荐答案

您可以使用 curl_multi ,它在一个curl句柄下内部触发多个单独的请求。

You can use curl_multi, which internally fires off multiple separate requests under a single curl handle.

但PHP本身不以任何方式/形状/形式多线程并且不会允许事物并行运行,除非通过严重的黑客攻击(多个并行脚本,一个脚本通过exec()启动多个后台任务等等)。

But otherwise PHP itself not in any way/shape/form "multithreaded" and will not allow things to run in parallel, except via gross hacks (multiple parallel scripts, one script firing up multiple background tasks via exec(), etc...).

这篇关于PHP并发HTTP请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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