是否可以使用PHP进行异步HTTP请求?

编程入门 行业动态 更新时间:2024-10-25 22:32:47
本文介绍了是否可以使用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请求?

本文发布于:2023-11-30 14:52:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1650401.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:可以使用   PHP   HTTP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!