How to create cron job using PHP?

前端 未结 12 1498
一整个雨季
一整个雨季 2020-11-21 05:50

I\'m new to using cron job. I don\'t even know how to write it. I have tried to search from internet, but I still don\'t understand it well. I want to create a cron job that

12条回答
  •  后悔当初
    2020-11-21 06:05

    In the same way you are trying to run cron.php, you can run another PHP script. You will have to do so via the CLI interface though.

    #!/usr/bin/env php
    

    Then, add an entry to the crontab:

    * * * * * /usr/bin/php -f /usr/local/bin/run.php &> /dev/null
    

    If the run.php script had executable permissions, it could be listed directly in the crontab, without the /usr/bin/php part as well. The 'env php' part, in the script, would find the appropriate program to actually run the PHP code. So, for the 'executable' version - add executable permission to the file:

    chmod +x /usr/local/bin/run.php
    

    and then, add the following entry into crontab:

    * * * * * /usr/local/bin/run.php &> /dev/null
    

提交回复
热议问题