duannaiying9662 2013-11-13 12:36
浏览 69
已采纳

PHP设置进程的间隔

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:

  1. xml file read with php
  2. Echo the results.

  3. --->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)

  • 写回答

2条回答 默认 最新

  • douxin9135 2013-11-13 13:05
    关注

    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()
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?