Codeigniter is_cli_request() stops cpanel cron job from working

后端 未结 2 1589
自闭症患者
自闭症患者 2021-01-25 10:34

On my website I use cron job on cpanel.

I have this code below in the construct area of controller but it stops the cpanel cron job from working.

if (!$t         


        
2条回答
  •  执念已碎
    2021-01-25 11:25

    To prevent direct access from a webpage:

    you need to add this line

    /* deny direct call from web browser */
    if (isset($_SERVER['REMOTE_ADDR'])) die('Permission denied.');
    

    with CI 3.0 you can

    Make your cron-jobs inaccessible from being loaded in the URL by checking the return value of is_cli().

    is_cli() returns TRUE if the application is run through the command line and FALSE if not.

    as by my comment, the cpanel cron job pattern is:

    /usr/bin/php /var/www/website/public_html/cli.php controller method

    ,

    see docs here

    related post

提交回复
热议问题