greenheart Posted October 15, 2009 Share Posted October 15, 2009 Hello, in my simple script I call an api which effectively involves me getting an xml file. However the problem is everytime I get a visitor to the webpage it calls the API which means lots of wasteful calls to the API as the data their end isn't updated more than once an hour or something. I know how to cache and retrieve the data but what command/s are used to tell my server only to call the API every hour and thus update the cache? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/177796-how-to-limit-the-calls-to-an-api/ Share on other sites More sharing options...
jonsjava Posted October 15, 2009 Share Posted October 15, 2009 call the API from a different file, and have it post to your caching system. That way, the main page isn't making the call, so there isn't a waste of the calls. Quote Link to comment https://forums.phpfreaks.com/topic/177796-how-to-limit-the-calls-to-an-api/#findComment-937552 Share on other sites More sharing options...
greenheart Posted October 15, 2009 Author Share Posted October 15, 2009 But how do I set it so it calls the API every hour? What command/function do I need to use? Quote Link to comment https://forums.phpfreaks.com/topic/177796-how-to-limit-the-calls-to-an-api/#findComment-937754 Share on other sites More sharing options...
Bisa Posted October 15, 2009 Share Posted October 15, 2009 My guess is you would need a cron job (something repeatedly executed by the server with a user specified time interval, in your case once every 60min) Can't help you with crons thou =/ Quote Link to comment https://forums.phpfreaks.com/topic/177796-how-to-limit-the-calls-to-an-api/#findComment-937757 Share on other sites More sharing options...
greenheart Posted October 16, 2009 Author Share Posted October 16, 2009 Yes! Looked it up on google and cron is exactly what I was looking for. I found some examples which I can adapt. Cheers. Quote Link to comment https://forums.phpfreaks.com/topic/177796-how-to-limit-the-calls-to-an-api/#findComment-937763 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.