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条)

报告相同问题?

悬赏问题

  • ¥15 matlab基于鲸鱼算法优化vmd
  • ¥20 PCB设计与制作问答
  • ¥20 课堂跑如何下载ppt
  • ¥15 有没有哥看着画下电路
  • ¥15 STM32阿里云平台显示不了传感器采集的数据
  • ¥20 三菱FX系列PLC上位机串口下指令置位M64和M65,这两条指令分别是什么呢?
  • ¥15 有关结冰模拟程序咨询
  • ¥15 ubuntu服务器配置dns域名后无法访问其他域名
  • ¥50 本人复制了一个关于股票指标的代码,但是运行失败,有没有人帮我解决一下
  • ¥50 用matlab和numeca做透平机械流体力学和热力学模拟 价格可议