I am using Codeigniter for my website. I have to use a Cron job to run one of the controller functions. I used all these options in a Cron job but all not working.
0 * * * * php /home/username/public_html/ /controller/method
0 * * * * php /home/username/public_html/ controller/method
0 * * * * php /home/username/public_html/ controller method
0 * * * * php /home/username/public_html/index.php /controller/method
0 * * * * php /home/username/public_html/index.php controller/method
0 * * * * php /home/username/public_html/index.php controller method
wget -O /dev/null https://websiteurl/url >/dev/null {websiteurl = website url} {url = route url}
if I place any PHP file in the main directory then it works fine. but not working for Codeigniter.
You can create a cron.php file in the main directory
<?php
$argc = $_SERVER['argc'];
$argv = $_SERVER['argv'];
// INTERPRETTING INPUT
if ($argc > 1 && isset($argv[1])) {
$_SERVER['PATH_INFO'] = $argv[1];
$_SERVER['REQUEST_URI'] = $argv[1];
} else {
$_SERVER['PATH_INFO'] = '/crons/index';
$_SERVER['REQUEST_URI'] = '/crons/index';
}
set_time_limit(0);
require_once('index.php');
?>
I have used below cron
30 * * * * php /var/www/html/cron.php /controller/method
Work for me
I tried different options but unable to figure out the problem. But the below method solved my problem.
Created a file in the main directory. in this file, I used curl to call CodeIgniter URL.
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.website.com/call-desired-url');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 900);
$content = curl_exec($ch);
curl_close($ch);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.