问题
I am building a caching system to store Twitter API tweets as to avoid violating the hourly call limit.
I am storing the tweets in a database with a timestamp and then checking in PHP to see if the timestamp is an hour old, if so then I call the API again. At the moment I can't seem to get it working. Here is what I curently have (which I admit is most probably wrong!)
if($results->tweet_date <= strtotime('-1 hours')) {
//do api call
} else {
//call tweets from database
}
This doesn't seem to be working though. Can anyone point me in the right direction? Thanks!
回答1:
What about using the timestamp minus 3600?
if($results->tweet_date <= time() - 3600) {
//do api call
} else {
//call tweets from database
}
EDIT: If you want to use strtotime
, you can use strtotime('-1 hour')
to calculate the time (mind the hour instead of hours).
来源:https://stackoverflow.com/questions/12403189/how-to-check-if-a-timestamp-is-an-hour-old