Run a PHP script once every minute

百般思念 提交于 2019-12-29 07:44:34

问题


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


回答1:


You can run PHP code from the command line. e.g., if your PHP folder is in PATH:

php.exe C:\mycode\myfile.php

You can then set this up as a scheduled task in windows. Side note: be aware that certain things don't exist (and something exist in their place), e.g. Apache or IIS objects, as well as the full range of HTTP stuff.




回答2:


Set up a cron job.




回答3:


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.



来源:https://stackoverflow.com/questions/1521943/run-a-php-script-once-every-minute

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!