How to set cron job URL for CodeIgniter? - php

I am using CodeIgniter for my website. I have to use cron job to run one of controller function. I am using route in website. And also I am not using index.php in URL.
e.g. http://example.com/welcome/show, here welcome is my controller and show is function name of that controller.
I have used like this,
0 * * * * php /home/username/public_html/welcome/show
It is giving 'No such directory'
How can I set cron jon in cPanel for above URL.

Use:
php index.php welcome show
as command in your crontab. E.g.:
0 * * * * php /home/username/index.php welcome show
Source (ver. 2.2.0)
http://www.codeigniter.com/userguide2/general/cli.html
Source (ver. 3.*)
http://www.codeigniter.com/user_guide/general/cli.html
Source (ver. 4.*)
http://codeigniter.com/user_guide/cli/cli.html

I have used below cron
php /full-path-to-cron-file/cron.php /test/index
source: http://www.asim.pk/2009/05/14/creating-and-installing-crontabs-using-codeigniter/
This works for me.
Thanks to all

You can try with this one:
wget api.example.com/index.php/controller/function

You can also try:
0 * * * * /usr/bin/curl --silent --compressed http://example.com/welcome/show
Or localhost
0 * * * * /usr/bin/curl --silent --compressed http://localhost/welcome/show
I hope that is helpful.

/usr/local/bin/php /home/username/public_html/index.php controllername methodname
This worked for me.

Here is the cron I use
/usr/bin/php /home/pia/www/jobs/index.php cron newsletter
Explanation:
a) $_SERVER['DOCUMENT_ROOT'] = /home/pia/www
b) codeigniter website root = /home/pia/www/jobs
c) 'cron' = controller name
d) 'newsletter' = method name

I have done it as
00 09-18 * * 1-5 /usr/bin/php /var/www/html/app/index.php crontest
crontest is the name of the controller which also uses a model to pull data from the database and send mail periodically (between 9 AM to 6 PM on Monday to Friday every week)
I just viewed this page which explains very detail with example. Hope this will be useful to others as well.

I am using codeigniter 3.0.3 and my server is hostgator. For me, the below format is working fine
*/15 * * * * /opt/php55/bin/php /home/username/public_html/myapp/index.php reminders index
above command runs every 15 minutes, reminders in command is controller name and index is method name.

watch -n60 curl [your application path]/check_banalce/user_balance
in my case im using codeigniter and the above command executes the user_balance function which is found in check_balance controller every 60 sec.

On a Linux EC2 intance, this worked:
*/5 * * * * /usr/bin/php /var/www/html/cifolder/index.php [module] [function]

If you are using the Hostgator(or any other Linux server) then try this one.
/opt/cpanel/ea-php72/root/usr/bin/php /YOUR_HOME_DIRECTORY/YOUR_USERNAME/public_html/marketing/index.php welcome emailcampaign 1
for example for me its
/opt/cpanel/ea-php72/root/usr/bin/php /home3/adnan/public_html/index.php welcome emailcampaign 101
where
welcome is the controller name
emailcampaign is the function name of welcome controller
101 = First argument of url.

Set up cron jobs through cPanel using this procedure:
Log on to your cPanel Interface.
Go to ''Advanced' section.
Click on "Cron Jobs".
Select the specific time from the lists provided.
You should enter the command to run in the "Command" field.

* * * * * php index.php controllername functionname
1st * - minute,
2nd * - hour,
3rd * - day of month,
4th * - month,
5th * - day of week.
For more info visit : https://crontab.guru/

I am using hostgator's cPanel.
I have created a user controller and run_cron_data function inside the user controller.
Command: wget www.example.com/index.php/user/run_cron_data
See the below screenshot

If you are using cPanel then Use the following command:
/usr/bin/curl -k http://example.com/welcome/show
This works perfectly for me.

Related

Is it possible to use the same cron jobs for different subdirectories within the same domain name

I am working on a project in which I want to use the same cron job for different subdirectories within the same domain name like
www.abc.com/first
www.abc.com/second
www.abc.com/third
How can i do this can anyone please tell me?
Do some thing like this, this should run every 1 min for 3 website or sub directories . Note: It depends on your path.
* * * * * /usr/bin/php /www/virtual/username/first/cron.php > /dev/null 2>&1
* * * * * /usr/bin/php /www/virtual/username/second/cron.php > /dev/null 2>&1
* * * * * /usr/bin/php /www/virtual/username/third/cron.php > /dev/null 2>&
Let me know if you need more assistance.
Is mytrendin.com on the same Server as abc.com?

I need to run cronjob every 5 minutes plus offset time

Currently my cron job is scheduled to every 5 minutes.
*/5 * * * * curl http://localhost/aa_portal/refresh_id.php
currently this schedule is running every 5 minutes
Example : 12.00AM, 12.05AM, 12.10AM, ....
I need to run this Job every 5 minutes by 2 min gap
Example : 12.02AM, 12.07AM, 12.12AM, ....
Can I change this cron job command to full fill this requirement
Following the KISS principle you could just list the minutes
2,7,12,17,22,27,32,37,42,47,52,57
Example:
2,7,12,17,22,27,32,37,42,47,52,57 * * * * curl http://localhost/aa_portal/refresh_id.php
The following worked for me on Debian 11 using cron.
2-59/5 * * * * myCommand
0 2-59/5 * * * ? this worked for me, but it's java

crontab not working in kohana freamwork

I'm using crontab to call my function.
but it is not working.
My function is working browser as well as in postman too.
====> MY FUNCTION
public function action_dateNotification() {
$sql = "INSERT INTO testcrown(name) VALUES('nitin')";
DB::query(Database::INSERT, $sql)->execute();
echo "inserted";
}
below url is working in browser and postman. When we invoke this url entry get save into database.
http://www.nkg.com/index.php/api/firebasenotification/dateNotification
I have set above url in crontab -e file
1 * * * * php index.php --uri=controller/api/firebasenotification/dateNotification
My project kohana version 3.1.3.1.
Use Kohana Task or:
1 * * * * wget http://example.com/controller/api/firebasenotification/dateNotification

laravel 4.2 liebig package work on localhost but fail in server cron job command

i want to fire some function to get news about football from rss
i used laravel4.2 https://github.com/liebig/cron
as that
Event::listen('cron.collectJobs', function() {
Cron::add('football', '* * * * *', function() {
//the controller of function
$news=new News_feedController();
$news->football();
return 'success';
});
});
$report = Cron::run();
it work correctly when i use cmd
php artisan cron:run
in my computer
but when use the server cron job command
/usr/bin/php /home/public_html/interestoo.com/artisan cron:run
i don't find any change in
cron_job
table but find data in
cron_manager
table
and the cron job function did not work
i'm sure that the path
/home/sfathy/public_html/interestoo.com/
in command is true and does not find any reason for that problem
any help please.
you might want to give this a try usr/bin/php5 /home/public_html/interestoo.com/artisan cron:run due to laravel required php>=5.4

CRON command with Yii

I have a code that will automatic create a sitemap.xml . My Url look like this : http://example.com/sitemap
But now I want it to automatic run every minutes (just test) . I tried 2 way but none of them work :
first is call through URL ,ex:
*/1 * * * * wget http://example.com/sitemap
or
*/5 * * * * curl http://example.com/check
second is call throught php file , I'm using Yii so i'm not sure what the file .php is ? is this controller file or something else?
*/1 * * * * /usr/bin/php /home/domains/public_html/protected/modules/homepage/controller/HomepageController.php
my Sitemap action's code inside HomepageController.php
Use console command for running CRON calls. For example, create SitemapCommand.php (place it in protected/command/) with following code:
class SitemapCommand extends CConsoleCommand
{
public function actionGenerate($debug=0)
{
#generating of sitemap
}
}
Then add line like this, to your crontab file:
*/1 * * * * /usr/bin/php /home/domains/public_html/protected/yiic.php sitemap generate
You have to put something like this in your linux cron tab->
http://www.Yourwebstieaddress.com/index.php (use one spacebar) Controller_name (use one spacebar) function_name
it will definitely work

Categories