I have an API fetcher script that reads values from XML files and updates data to mysql. It updates the database everytime it's called via ajax.
Now I want to set an interval for about a day before the query gets updated. Which php function or method should I use?
I think I should make myself a little more clear, these are the steps:
Echo the results.
--->If (mysql updated time > 24*60*60 seconds) update the db
--->if not, do nothing.
I can't figure out how should I process the step (3)
Well! as far as i understood your question. I think you should do with SQL not with PHP.
Save update time in db with query of Insert. And call a stored procedure every time you update. like in MySQL:
Begin
//Adding updtime column value into a Variable called @a
select @a:=updtime from abc order by id desc limit 1;
//DATE_ADD() is a function of MySQL to get Time after adding Hours or Minutes etc. More can be found in MySQL Manual online
if DATE_ADD(@a, INTERVAL 24 HOUR) > now()
then insert into abc values ('XML',now());
end if;
End
You can also do it without a variable and that would be much better as
if DATE_ADD((select updtime from abc order by id desc limit 1), INTERVAL 24 HOUR) > now()
The best solution that I can think of is a Cron Job.