Home > Backend Development > PHP Tutorial > What is the best solution for loop reading with paging interface?

What is the best solution for loop reading with paging interface?

PHP中文网
Release: 2016-08-27 09:06:48
Original
2028 people have browsed it


Currently, we need to read third-party interface data. The amount of data is relatively large, so the third party uses paging. My current plan is to call the curl reading interface method in a loop, and then convert the json data into Array, when splicing the array, perform data filtering and warehousing operation, but due to the instability of the third-party interface, the reading may fail. Is there a better solution?

Reply content:

Currently, we need to read third-party interface data. The amount of data is relatively large, so the third party uses paging. My current plan is to call the curl reading interface method in a loop, and then add json The data is converted into an array, the array is spliced, and the data is filtered and stored in the database. However, due to the instability of the third-party interface, the reading may fail. Is there a better solution?


If the amount of data is large, you can use a scheduled script to pull it.
When pulling, first sort by a field such as auto-incrementing id, so as to avoid the problem of paging data changes.
Then when the script is executed or when the loop ends, write down the largest ID, and then bring a condition greater than this value the next time it is executed.

Then when the script is executed, if the interface call fails, you can try to pull it again several times. If it fails, stop the script execution, then write down the id, and then give an early warning message and manual intervention.
Well, a simple idea


1. It is recommended to establish a crawling original database, whether it is id or md5, to ensure the uniqueness of single data capture
2. The interface is unstable, and curl failure handling can be handled through exception handling, etc. Try your best to ensure that the data capture is successful
3. Be prepared to capture data repeatedly. Based on 1, ensure that the data will not be processed repeatedly

The above is the optimal solution for loop reading with paging interface, and more For more related content, please pay attention to the PHP Chinese website (m.sbmmt.com)!


Related labels:
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template