PHP Curl script to pull data from remote server every 10 minutes

匆匆过客 提交于 2019-12-02 12:34:49

问题


I'm trying to create a PHP script which pulls xml data (text and images) from a remote server and inserts it in a local database. I need to run this script every 10 minutes or so (and overwrite the existing data in my db)... if I don't get a response from the server after about a minute, I would like the request to abort until the next time the script runs 10 minutes later. Can anyone please either give me some idea as to how I can achieve this or point me to a tutorial that explains it in fairly simple terms?

Thanks!

EDIT: I'm looking for help with the PHP script itself, not sure that was clear in my initial post.


回答1:


You can create a run of the mill curl script that connects to a remote server and fetches data, inserts into your db, set limits and exceptions. Then create an entry in crontab to run this script every 10 minutes. I have a similar setup running for one of my website which fetches data from stock exchange and updates a local cache, another script has the task of consuming the cache as and when required.




回答2:


Do you know about cron jobs? They're used to schedule periodic tasks like executing scripts from the server.

http://en.wikipedia.org/wiki/Cron




回答3:


Here's a good primer on how Cron Jobs work: http://www.webmasters-central.com/article-blog/tutorials/cron-tutorial-managing-cron-tab-or-cron-job-is-easy/



来源:https://stackoverflow.com/questions/7051038/php-curl-script-to-pull-data-from-remote-server-every-10-minutes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!