Run a PHP script once every minute

前端 未结 3 1564
执笔经年
执笔经年 2020-12-19 08:50

I need to execute my PHP code every minute. Is there any way to do that?

3条回答
  •  我在风中等你
    2020-12-19 09:03

    If you don't want to use cron; you could write a script to call it at the top of the minute

    #!/bin/bash
    while [ true ]; do 
      if [ $(expr $(date +%s) % 60) -eq 0 ]; then 
        echo "top o da minute";
        #put php script here
      fi; 
      sleep 1; 
    done
    

    Advantage/Disadvantage is that you will only spawn one copy of the script if it takes longer than a minute to complete.

提交回复
热议问题