I have got a page which queues up emails in beanstalked.
The script works as intended, the emails get fired when i have a queue listener, ie.
php artisan queue:listen
But when i remove the listener and add it to the crob job
* * * * * /usr/bin/php /var/www/huge/artisan queue:listen
The emails don't get fired.
Any ideas?
Had this exact same issue the other day, you probably just need to cd in to the directory where Artisan is located first. Try the following:
* * * * * cd /var/www/huge/ && /usr/bin/php artisan queue:listen
Also, are you sure the currently in use PHP CLI is located at /usr/bin and not /usr/local/bin?
If the above doesn't work try:
* * * * * cd /var/www/huge/ && /usr/local/bin/php artisan queue:listen
Related
I have a hard time running cron job on Digitalocean. I noticed there are two different cron files, I get to one by getting to /etc/crontab and other one by entering the command crontab -e.
To make it more confusing, both of those have somewhat different "layout". First one:
* * * * * root php /var/www/Laravel artisan schedule:run >> /home/laravel.log
and second one:
* * * * * php /var/www/Laravel artisan schedule:run >> laravel.log
Here is Laravel scheduler part:
protected $commands = [
'App\Console\Commands\SyncAPIs',
];
/**
* Define the application's command schedule.
*
* #param \Illuminate\Console\Scheduling\Schedule $schedule
* #return void
*/
protected function schedule(Schedule $schedule)
{
$schedule->command('media:sync')->everyThirtyMinutes();
// sync for yesterday to eliminate discrepancies
$schedule->command('media:sync ' . Carbon::yesterday())->dailyAt(6);
}
The thing is that the laravel.log does get created, but I see nothing in it, and I don't know if my commands actually get ran. Does that mean that cron IS actually running? How can I debug the issue as I don't see in the database that cron filled it. When I go to the folder /var/www/Laravel and execute the commands which are supposed to be called in scheduler, dataabse fills correctly.
cd ~
crontab -u root -e
* * * * * php /var/www/laravelprojectname/artisan schedule:run 1>> /dev/null 2>&1
service cron restart
grep -i cron /var/log/syslog|tail -3
I think this should help
May be you need to change this line :
* * * * * php /var/www/Laravel artisan schedule:run >> laravel.log
to :
* * * * * /usr/bin/php /var/www/Laravel artisan schedule:run >> laravel.log
I found an answer being actually:
* * * * * php /var/www/Laravel/artisan schedule:run >> laravel.log
php works globally, but artisan needs to be shown the path which is in my Laravel main folder
I am trying to set up scheduler in Laravel.
Here is my crontab which I debugged and works fine - atleast with my cron job
* * * * * /bin/echo "foobar" >> /my_path/example.txt
I don't know if this one works:
* * * * * php /var/www/myproject/artisan schedule:run 1>> /dev/null 2>&1
Here is my schedule function in Kernel:
protected function schedule(Schedule $schedule)
{
$schedule->command('inspire')
->everyMinute();
}
When I am in my project and try php artisan inspire it actually works, so I expected it to fire every minute, but it won't do anything. Nothing happens.
Any ideas?
This part just puts the output into oblivion so you'll never see it:
>> /dev/null 2>&1
Why not try:
* * * * * php /var/www/myproject/artisan schedule:run >> /my_path/example.txt
And check to see if the cron is run in /my_path/example.txt
The default inspire command essentially just echo's a quote so the only way to see it in a cron is to output it to a file on the server.
You can do this using something similar to this:
$schedule->command('inspire')->everyMinute()->appendOutputTo($filePath);
Further details: https://laravel.com/docs/5.4/scheduling#task-output
you should try something
like * * * * * cd /Path/TO/YOUR_PROJECT/ && php artisan schedule:run >> /dev/null 2>&1
Am also using laravel 4.2, Here is my Cron command which currently working good.
0 0 * * * /usr/local/bin/php /*****/******/public_html/artisan command:firemyevent
Hope It will help you.
in my case, I had to explicity a php version compatible with laravel, in my cron job:
cd /path/to/my/project && /usr/local/bin/ea-php71 artisan schedule:run > /dev/null 2>&1
I made it run in mac through:
* * * * * cd /Applications/XAMPP/xamppfiles/htdocs/rcraze && /usr/local/bin/php artisan schedule:run >> /dev/null 2>&1
You have to put full path of PHP (you can get it through whereis php command in MAC terminal) and pull path of your project.
I am trying to run a Symfony2 command with a cron job but I get an error that the environment is not found. Here is my cron job:
* * * * * /usr/local/bin/php /usr/lib/myApp/app/console >> /usr/lib/myApp/forumLog.txt 2>&1
For now I am just trying to make app/console work and the expected output is a list with all commands. The error that I get is:
[Symfony\Component\Debug\Exception\ContextErrorException]
User Error: The environment was not found
Do you have any idea what is wrong and what is the correct way to run symfony2 commands through cronjob?
In my own Symfony-console running cronjobs, I usually have cron run a shell script, that first changes into the apprppriate directory, and then runs the console command.
Here's an example that has been running for a year or two:
File: /etc/cron.d/systemChecks (run a shell script as user: www-user)
10 7,19 * * * www-data /var/www/dir.../bin/liipMonitor.sh
File: /var/www/dir.../bin/liipMonitor.sh
#!/bin/sh
# Running at 7:10 and 19:10
cd /var/www/dir.../
bin/console --env=prod monitor:health --group=cli -q
I put the cron setup into their own files in /etc/cron.d but much the same would apply in any other crontab file. The shell script changes directory to the base directory of the project, and then runs bin/console.
Set the --env parameter in the cronjob command, like that:
* * * * * /usr/local/bin/php /usr/lib/myApp/app/console --env=prod >> /usr/lib/myApp/forumLog.txt 2>&1
I have a Laravel 5.1 site, and an artisan command set up that I can run manually without problems, but I cannot seem to get it to fire at a scheduled time.
I have a crontab set up on a digital ocean server, the contents of the file are
HELL=/bin/bash
MAILTO=""
* * * * * php /var/www/{domain}/artisan schedule:run 1>> /dev/null 2>&1
where {domain} is the actual domain.
In my kernel.php file I have the following
protected function schedule(Schedule $schedule)
{
$schedule->command('migrate:existing-users')->dailyAt('10:25');
}
There's nothing in the laravel log file that offers any clues, it just seems like nothing it happening.
How can I check if the cron is set up correctly?
EDIT:
It seems the cron tab was set up under the root user, so I have also set up another one under www-data, and put this simple line in both
* * * * * echo 'run this command every minute'
with my email address in the MAILTO= line, but nothing gets emailed to me on either crontab
I have custom Artisan commands that run locally as well as on my production server when I am SSH'd in, but are unavailable to any cron jobs. I've even tried running it as the user the cron job runs as and it works fine from my console.
When I run php artisan in the above settings, my custom commands are listed and available. However, they are not listed when I run php artisan as a cron job.
Furthermore, trying to run the custom command php artisan subjects:calculate as a cron job results in the following error:
[InvalidArgumentException]
There are no commands defined in the "subjects" namespace.
I was fighting with the same error and I found the solution.
First failed attempts
*/5 * * * * /usr/bin/php /home/mysite/public_html/artisan my:command
*/5 * * * * php /home/mysite/public_html/artisan my:command
Solution
*/5 * * * * /usr/local/bin/php /home/mysite/public_html/artisan my:command
Be sure to add the command to app/start/artisan.php file:
Artisan::add(new SubjectsCommand);
or if you are using the IOC container:
Artisan:resolve('SubjectsCommand');
Then run the CronJob from the folder of the app:
00 09-18 * * 1-5 php /path/to/yourapp/artisan subjects:calculate
or
00 09-18 * * 1-5 /usr/bin/php /path/to/yourapp/artisan subjects:calculate
At least for me that worked:
class Kernel extends ConsoleKernel
{
protected $commands = [
// Commands\YourCommand::class,
];
}
Just added my command to the list of command kernel.
You probable need to make sure artisan is running from the correct directory
cd /path/to/yourproject && php artisan subjects:calculate