How to schedule dynamic function with cron job?

后端 未结 6 1962
無奈伤痛
無奈伤痛 2021-01-02 06:02

I want to know how I can schedule a dynamic(auto populated data) function to auto run everyday at saved time?

Let\'s say I have a form that once the button is clicke

6条回答
  •  没有蜡笔的小新
    2021-01-02 07:00

    If I understand correctly, I think something like this may work for you, using the hours as keys to the function you want run, in a cron set to run every two hours:

    $listArray = Array(8=>"list1_function",10=>"list2_function");//etc...
    $hour = Date("G");
    
    if(array_key_exists($hour,$listArray))
    {
        $listArray[$hour]();
    }
    
    function list1_function()
    {
         echo "do list 1 stuff";
    }
    
    function list2_function()
    {
         echo "do list 2 stuff";
     }
    

提交回复
热议问题