creating schedule task without Cron job

前端 未结 5 1405
野趣味
野趣味 2020-12-30 17:29

Scheduled task needs to be created but its not possible to use Cron job (there is a warning from hosting provider that \"running the cron Job more than once within a 45-minu

5条回答
  •  情书的邮戳
    2020-12-30 17:58

    if you have shell access you could execute a php script via the shell

    something like this would be an endless loop, that would sleep 60 seconds execute, collect garbage and repeat until the end of time.

    while(true) {
        sleep(60);
        //script here
    
    
        //end your script
    }
    

    or you could do a "poor mans cron" with ajax or meta refresh. i've done it before. basically, you just place a redirect with either javascript or html's meta refresh at the beggining of your script. access this script from your browser, and just leave it open. it'll refresh every 60 seconds, just like a cronjob.

    yet another alternative to a cronjob, would be a bash script such as:

    #!/bin/bash
    while :
    
    do
    sleep 60
     wget http://127.0.0.1/path/to/cronjob.php -O Temp --delete-after
    
    done
    

    all this being said, you probably will get caught by the host and get terminated anyway.

    So your best solution:

    go and sign up for a 5-10 dollar a month vps, and say good bye to shared hosting and hello to running your own little server.

    if you do this, you can even stop using crappy php and use facebook's hhvm instead and enjoy its awesome performance.

提交回复
热议问题