Scheduling php scripts

前端 未结 3 2111
抹茶落季
抹茶落季 2020-12-18 10:47

I want to create some function to schedule php scripts,for example if i want tu run page.php at 12/12/2012 12:12 i can call

schedule_script(\'12/12/2012 12:1         


        
3条回答
  •  情书的邮戳
    2020-12-18 11:39

    There's a PHP function which lets you delay script execution till a point in time.

    So let's say I have cron.php:

    
    

    And your classes/functions file:

    // Const form K2F - Are we on windows?
    define('ISWIN', strpos(strtolower(php_uname()),'win')!==false &&
                    strpos(strtolower(php_uname()),'darwin')===false );
    
    // Function from K2F - runs a shell command without waiting (works on all OSes)
    function run($cmd){
        ISWIN ? pclose(popen('start /B '.$cmd,'r')) : exec($cmd.' > /dev/null &');
    }
    
    script_schedule($script,$time){
        if(is_string($time))$time=strtotime($time);
        run('php -f -- schedule '.escapeshellarg($script).' '.$time);
    }
    
    script_interval($script,$mseconds){
        run('php -f -- interval '.escapeshellarg($script).' '.$mseconds);
    }
    

    It ought to work. By the way, K2F is this framework that makes your dreams come true..faster. ;). Cheers.

    Edit: If you still want the parts about counting running jobs and/or deleting(stopping) them, I can help you out with it as well. Just reply to my post and we'll follow up.

提交回复
热议问题