Cron jobs in codeigniter

后端 未结 5 603
花落未央
花落未央 2020-12-10 07:16

I am trying to do a cron job with a site built in CodeIgniter - I\'ve got access to the CPanel cron feature can anyone suggest the best way to setup a cron job using CPanel?

相关标签:
5条回答
  • 2020-12-10 07:56

    For me the easier way of doing this is using cURL and executing the url in the cron:

    curl http://admin.com/sites/publish/
    

    If you need to secure the url, you could send data via post using:

    curl -X POST -d "apikey=yourapikey&another=variable" http://admin.com/sites/publish/
    

    This way you don't have to fight with php parameters and different configurations.

    0 讨论(0)
  • 2020-12-10 08:00

    I do this such way, create folder cron

    /application
    /cron
       my_task.php
    /public
    

    make script for each cron job /cron/my_task.php with content

    <?  $_SERVER["SCRIPT_URL"] = "/controllerName/MethodName"; // you can set url in routes if you want
        $_SERVER["HTTP_HOST"] = "your_site_address.com"; // without http://www
        require(dirname(__FILE__) . "/../public/index.php");  // path to index.php
     ?>  
    

    make controller Cron like others, but add validation on IP in __construct

    and finaly run like

    1 10 * * * cd /path_to_site_folder/cron/ && usr/local/bin/php /path_to_site_folder/cron/my_task.php >> path_to_log/some.log
    
    0 讨论(0)
  • 2020-12-10 08:06

    just use this command and paste it.

    wget www.example.com/index.php/controller/function
    
    0 讨论(0)
  • 2020-12-10 08:09

    For Cronjob try this to access command line controller, functions and params:

    php index.php/controller/function/param1/param2/param3 etc
    

    or

    php index.php controller function param1 param2 param3 etc
    
    0 讨论(0)
  • 2020-12-10 08:11

    Best way is to call from the command line in the cron job...

    php /path/to/index.php controller >> /dev/null
    

    You can run controllers via the command line in CI, see here.

    0 讨论(0)
提交回复
热议问题