curl 分页获取十几万的数据 服务器超时,如何解决?

WBOY
Release: 2016-06-06 20:45:23
Original
1157 people have browsed it

curl 获取api的接口数据,while循环page++接收处理数据,每页100条数据。数据总共十几万条。老是服务器超时,如何解决?
max_execution_time set_time_limit

回复内容:

curl 获取api的接口数据,while循环page++接收处理数据,每页100条数据。数据总共十几万条。老是服务器超时,如何解决?
max_execution_time set_time_limit

人家受不了了,你就弄慢点啊,sleep一下~

如果是坐蜘蛛抓人家页面内容,建议利用程序通过代理IP去抓取,否则人家看你抓取频繁直接封IP,就麻烦了;
如果是自己内部的,就像 @ChanneW 说的,sleep时间长点,慢点抓

确实有这样的问题,最好的解决办法是结合数据库做一个采集应用,采集成功的修改状态为1,采集不到的修改状态为0,然后通过定时脚本,轮询采集
分析失败原因,是不是上班时间段访问量比较大,导致的,可以错开该时间段,比如晚上/凌晨采集,希望能帮到你。

为防止超时,还可以进行不停刷新跳转。重新进行请求。

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!