简体   繁体   English

同时加载多个URL

[英]Load multiple URLs at the same time

I have a list of resources which serve me XML feed. 我有为我提供XML提要的资源列表。 I need to loop through them and update database accordingly. 我需要遍历它们并相应地更新数据库。

So imagine we have 100 URLs. 假设我们有100个网址。 I need to start fetching XML from them at the same time, then, after some time parsing of all XML feeds will be finished, and I need to catch this moment in order to update "Last refreshed time". 我需要同时开始从它们中获取XML,然后,在一段时间之后,所有XML提要的解析都将完成,并且我需要抓住这一时刻以便更新“上次刷新时间”。

I use simplexml_load_url for the purpose of parsing XML. 我使用simplexml_load_url来解析XML。

Them most important thing is time issue, I tried fetching XMLs one-by-one and it took around 50 seconds for 20 URLs. 他们最重要的是时间问题,我尝试一次一对一地获取XML,花20个URL大约花费了50秒。

How can I achieve this? 我该如何实现? Number of URLs might be around 300-500. URL的数量可能约为300-500。

Thanks 谢谢

Take a look at GuzzleHttp that can do the concurrent file processing. 看一下可以进行并发文件处理的GuzzleHttp Much more efficient and fast if it fits your case. 如果适合您的情况,效率和速度将大大提高。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM