Welcome Guest, Not a member yet? Register   Sign In
How to modify cron command in CodeIgniter?
#1

I'm having trouble setting up cron jobs on a CodeIgniter site hosted on a shared host with cPanel. While the cron script works when run via a browser, I've tried running it with both curl and wget in cron, but neither method seems to work. Could this be due to the site being SSL and all HTTP requests being rewritten to HTTPS using htaccess? I'm also unsure if the host may have disabled cron for some reason. How can I modify the example command given in an article for my CI setup, which has a controller located in a subdirectory and has the index.php disabled?
Reply
#2

(This post was last modified: 04-18-2023, 12:31 AM by SubrataJ.)

(04-17-2023, 10:42 PM)JohnSonandrbt Wrote: I'm having trouble setting up cron jobs on a CodeIgniter site hosted on a shared host with cPanel. While the cron script works when run via a browser, I've tried running it with both curl and wget in cron, but neither method seems to work. Could this be due to the site being SSL and all HTTP requests being rewritten to HTTPS using htaccess? I'm also unsure if the host may have disabled cron for some reason. How can I modify the example command given in an article for my CI setup, which has a controller located in a subdirectory and has the index.php disabled?

let's consider this is your cron command of Cpanel - /usr/local/bin/php /home/[TEST]/public_html/public/index.php cron check-recurring

Now you have to set the route in order it make it work properly
PHP Code:
$routes->cli('cron/check-recurring''Cron::checkRecurring'); 

If you have controller in a subdirectory you can use this 
PHP Code:
$routes->group('cron', ['namespace' => 'App\Controllers\Clirequest'], function ($routes) {
   $routes->cli('check-recurring''Cron::checkRecurring');
}); 

FYI get post or any other method won't work you have to use cli.

Give it a shot, at least it's still working for me.
Learning Codeigniter 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB