Run a Cron Job In Cpanel with CURL - php

I have a code in laravel, I want to setup a cron job in cpanel But I don't know how to. I saw several examples that has file name to cron, but I am using Laravel so how can I point this to URL route?
/usr/bin/curl https://example.com/cron_route
I am not sure is this correct method or I can do that in different way, well I canot use laravel artisan scheduler, I have all custom code and custom Controller.
can anyone help me out with this?

Try this command
1 1 * * 0 /usr/bin/curl -m 120 -s https://example.com/cron_route &>/dev/null

To add cronjob using command line, use this command
0 2 * * * wget -q -O /dev/null http://example.com/cron_script
See for reference : https://crontab.guru/

Related

Scheduling jobs in Laravel

I created a command in laravel "update:date" and "php artisan list" successfully lists it. I am able to execute it using "php artisan update:date"
Kernel.php:
protected $commands = [
'Snuba\Console\Commands\Inspire',
'Snuba\Console\Commands\UpdateDate'
];
protected function schedule(Schedule $schedule)
{
$schedule->command('inspire')
->hourly();
$schedule->command('update:date')
->everyMinute();
}
I configured it to run every minute as given above. Do I need to configure anything else ? I think laravel should automatically register it as cron task on ubuntu server.
I think laravel should automatically register it as cron task on
ubuntu server.
No, you have to start it like:
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
Starting The Scheduler
When using the scheduler, you only need to add the following Cron entry to your server. If you do not know how to add Cron entries to your server, consider using a service such as Laravel Forge which can manage the Cron entries for you
Reference
Another Answer
I just noticed:
Call to undefined method Illuminate\Console\Scheduling\Event::everyMinute()
I followed the documentation and thought this is a valid method call. I found that everyMinute() is no more valid in laravel 5+. So, I used cron expression instead.
Laravel's command scheduler allows you to fluently and expressively define your command schedule within Laravel itself. For more go through following link laravel task scheduling
If you have access to SSH
run command crontab -e
insert this line:
php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
which will run all your specified crons as there specified times.
If you have cpanel then under crontab add the above line on command
If ->everyMinute does not exist, please use ->cron('*/1 * * * * *') to set every minute. Or override class laravel.com/api/5.x/Illuminate/Console/Scheduling/Event.html
If cron job not working, run command crontab -e and add this line without single quote
'* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1'
After do this I think it works perfectly.

Task schedular of laravel not working properly on server

I am able to execute individual artisan commands on server using putty cli. for eg.
php artisan inspire
and other custom commands related to database, they work fine while using putty. Also i put them in kernel.php 's schedule funtion like this
protected function schedule(Schedule $schedule){
$schedule->command('customcommand:execute')->everyMinute();
}
when i run this command using putty
php artisan schedule:run
it also works fine.
problem is that i am not able to execute schedule:run command via servers cron job.. command looks like this on server
php -d register_argc_argv=On /path/to/artisan schedule:run >> /dev/null 2>&1
funny thing is i am able to execute individual commands via servers cron job
i.e.
php -d register_argc_argv=On /path/to/artisan customcommand:execute >> /dev/null 2>&1
works as well...
only that schedule command is not working.
also it does not show any errors..
also if I dont add '-d register_argc_argv=On', i get exception 'ErrorException' with message 'Invalid argument supplied for foreach()
again here by server i mean cPanal, i have added this command under 'cron jobs'
The ini directive register_argc_argv was disabled on the php.ini and I needed to enable it explicitly on each call in order to accept argc and argv parameters. Luckily I easily solved this problem using exec instead of command
$schedule->exec('php -d register_argc_argv=On /path/to/artisan sms:bulk-send')
Use your command instead of sms:bulk-send Then it will be work.
* * * * * /usr/local/bin/ea-php71 /home/your_domain/artisan schedule:run >> /dev/null 2>&1
first ,
which php
to get which php you're using now
then change your cron job command like
* * * * * /path/to/your/php /path/to/your/project/artisan schedule:run
specify which php and project you are using
for example * * * * * /usr/local/bin/php /home/user/project/artisan schedule:run
it works for me

Run PHP script in crontab only works when exporting to a file

On CentOS release 6.5 (Final):
I know that usually I just need to use the following command in crontab to run a php script.
0 * * * * /usr/local/bin/php absolute_path_file_to_the_script.php
But, recently, it stopped working. The only work around is to use the following command
0 * * * * /usr/local/bin/php absolute_path_file_to_the_script.php > log
But I would rather not to output anything to log for now.
So, I even tried
0 * * * * /bin/sh -c "/usr/local/bin/php absolute_path_file_to_the_script.php"
But the above commend is again not working in crontab (it works if I type in the shell directly).
And I am sure that the above command did run in crontab for a second with
ps ux, and then it stopped executing.
Any ideas on how to run the command properly without logging?
Try run that command (only php, without cron settings) from terminal and show result
Both answers from Marc and Greg work:
> /dev/null
or
> /dev/null 2>&1

How to set cron path?? Any easy way

I set
use /usr/local/bin/php /home2/bollyzz1/public_html/Bollyzz/latest_auditions_by_email.php
Error:
/usr/local/cpanel/bin/jailshell: use: command not found
Login to your cPanel and click Cronjobs under the Advanced section
Enter the following command in the Command to run field.
lynx -source "http://www.yourdomain.com/Bollyzz/latest_auditions_by_email.php" > /dev/null
Make your crone file path like this.
/usr/bin/php -q /home2/bollyzz1/public_html/Bollyzz/latest_auditions_by_email.php
Use wget command
wget http://domain.com/latest_auditions_by_email.php
set your time ( * * * * *) and check

How can i set a cron job in Zpanel

in C panel we can set url in cron job like
wget example.com/homes/action
Or
absolute path
/usr/bin/php -q /home/mohanphp/www/quote_bot/sms_cron.php
but Zpanel dose not support full url
and i want to call an action (in Cakephp eg http://abc.com/homes/corn_job/daily/ )
in c panel there is no problem but Zpenal how to do this ??
thanks
You can better check the link set a cron job in Zpanel.
touch /etc/cron.d/zdaemon
echo "*/5 * * * * root /usr/bin/php -q /etc/zpanel/panel/bin/daemon.php >> /dev/null 2>&1" >> /etc/cron.d/zdaemon
chmod 644 /etc/cron.d/zdaemon
If you are trying to run the URL, just because you want to run an action of a cakephp controller. Then you should try to use a dispatcher, which will let you execute a controller action from the command prompt and then you can setup the cron as normal in zpanel.
More information about the cron dispatcher could be found here:
http://colorblindprogramming.com/cronjobs-in-cakephp-2-in-5-steps

Categories