是否可以使用PHP进行异步HTTP请求? [英] Is making asynchronous HTTP requests possible with PHP?

查看:109
本文介绍了是否可以使用PHP进行异步HTTP请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个PHP脚本,需要从远程服务器下载多个文件。目前我只是有一个循环下载和处理文件与cURL,这意味着它不开始下载一个文件,直到前一个完成 - 这增加了脚本运行时间显着。

I have a PHP script that needs to download several files from a remote server. At the moment I just have a loop downloading and processing the files with cURL, which means that it doesn't start downloading one file until the previous one is finished - this increases the script run time significantly.

是否可以启动多个cURL实例,例如,同时异步下载这些文件,而不等待前一个完成?

Would it be possible to start several instances of cURL, for example, to asynchronously download these files at the same time without waiting for the previous one to finish? If so, how would this be accomplished?

推荐答案

是的。

多重引用PHP库(或参见:已归档的Google代码项目)。它是一个多线程的CURL库。

There is the multirequest PHP library (or see: archived Google Code project). It's a multi-threaded CURL library.

作为另一个解决方案,你可以编写一个脚本,用一种支持线程的语言,如Ruby或Python。然后,只需用PHP调用脚本。看起来很简单。

As another solution, you could write a script that does that in a language that supports threading, like Ruby or Python. Then, just call the script with PHP. Seems rather simple.

这篇关于是否可以使用PHP进行异步HTTP请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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