简体   繁体   中英

Run a PHP script once every minute

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

You can run PHP code from the command line. eg, 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), eg Apache or IIS objects, as well as the full range of HTTP stuff.

设置一个cron作业。

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.

 <meta http-equiv="refresh" content="60" />

A very simple solution would be to add this html tag to your page. The page will reload every content seconds, and of course, execute again the php code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM