Codeigniter cron job not working
the steps to prepare CodeIgniter 2.x for cron-jobs via CLI (command line interface):
1st: create a copy of your root index.php
file and save it in your root as cli.php
2nd: in your cli.php replace <?php
with this code:
#!/usr/local/bin/php
<?php
/* override normal limitations */
set_time_limit(0);
ini_set('memory_limit', '256M');
/* deny direct call from web browser */
if (isset($_SERVER['REMOTE_ADDR'])) die('Permission denied.');
/* constants */
define('CMD', 1);
/* manually set the URI path based on command line arguments... */
unset($argv[0]); /* except the first one */
$_SERVER['QUERY_STRING'] = $_SERVER['PATH_INFO'] = $_SERVER['REQUEST_URI'] = '/' . implode('/', $argv) . '/';
3rd: execute your cron job like this:
/usr/bin/php /var/www/website/public_html/cli.php controller method
where /var/www/website/public_html/
is your server's home directory, the location of your index.php
and cli.php
.
notes:
for CI 3.0 you find the necessary information here
database: you'll need to provide your db config settings in your controller method, as the cron job just executes the controller's method. So it doesn't know anything about any database settings!
$config['hostname'] = "localhost";
$config['username'] = "username_admin";
$config['password'] = "password";
//etc..
$this->db = $this->load->database($config, TRUE);
debug: just add a link in your html to run your controller's method like: index.php/controller/method
(remove that once you website is live)
source: very helpful
cpanel cron job not working in codeigniter project
This could be because a couple of things. First of all, it could be because you have the wrong path for php. The path on my server is:
/usr/bin/php
You can find your path by typing:
whereis php
Second of all, it could be because you haven't installed the packages neccesary on your server. You need the package php cli
sudo apt-get install php5-cli
Lastly, your cron controller may contain errors, I recommend checking your log file, if you see any errors. For me, the crontab job that is working is:
0 10 * * * /usr/bin/php /var/www/<MY_PROJECT_NAME>/index.php Cron
So yes you can indeed use capitalized words when calling your controller.
Codeigniter Cron job problems - CI Version 3.1.9
I found the answer, though not sure why this works:
I had to be more specific about the PHP version I was running:
/opt/cpanel/ea-php71/root/usr/bin/php /home/accountname/public_html/www/index.php controller method
I have no idea why this would make a difference, but it does work now. I do not have to use full path PHP calls for other cron jobs (that don't include controller and method) I just call:
/usr/bin/php /home/accountname/public_html/www/filename.php
Related Topics
Detect Main Colors in an Image with PHP
How to Fix Stream_Socket_Enable_Crypto(): Ssl Operation Failed with Code 1
How to Use Pdo's Prepared Statement for Order by and Limit Clauses
Warning: Session_Start() Failed: No Such File or Directory
Checking If All the Array Items Are Empty PHP
How to Get Current Time in Milliseconds in PHP
Require(Vendor/Autoload.Php): Failed to Open Stream
Is There a Biginteger Class in PHP
Remove .PHP Extension with PHP
Codeigniter Cron Job Not Working
PHP Artisan Make:Auth Command Is Not Defined
Beautiful Way to Remove Get-Variables with PHP
Sf2 Form:Error Neither the Property ... Nor One of the Methods "Get
How to Get the Value After the Hash in "Somepage.Php#Name"
Ajax File Download Using Jquery, PHP