I have php script ran by cron. When I manually run
php /var/www/html/ngix/hotshoponline.com/api/artisan schedule:run
it works fine, the script takes about 2 mins, and I can get the output I need.
But when it's called by cron like this
* * * * * php /var/www/html/ngix/hotshoponline.com/api/artisan schedule:run >> /dev/null 2>&1
it is not working
i tried with -f and tried with /usr/bin/php nothing is working
In order to see the possible errors, add an output file.
Something like this
* * * * * php /var/www/html/ngix/hotshoponline.com/api/artisan schedule:run > /var/log/error.log 2>&1
Then tail the error.log file to see if there are errors.
tail -f /var/log/error.log
Related
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 have good .php file when run directly via address bar browser.
But not process perfectly when run via cron job, may be it's just process first query msyql/first loop.
there is any special configuration for it?
My cron setup is
0 * * * * wget --spider -O - http://domain.com/cronjob >/dev/null 2>&1
See below example that is run your file on per minute
* * * * * /usr/bin/php /var/www/html/<your-file-name>
< and > are removed in <your-file-name>
I want to run a .php every 10 min with a cron job on Ubuntu.
This is my crontab:
*/10 * * * * php -f /var/www/html/gapi/src/test2.php >/dev/null 2>&1
And this is in the log file:
CRON[9994]: (root) CMD (php -f /var/www/html/gapi/src/test2.php >/dev/null 2>&1)
In this php is an api call, and I can see the api calls live at the dashboard of the api provider, so I know the php is not running every 10 mins.
I set the file permission to 755, what else can I do to make it work?
Updated Crontab:
*/10 * * * * php -f /var/www/html/gapi/src/test2.php
Try requesting the file through your web server rather than calling the script via the command line PHP interpreter.
*/10 * * * * wget -q -O /dev/null http://localhost/gapi/src/test2.php
(-q to suppress output, -O /dev/null to redirect file output so it doesn't save it)
or using curl instead:
*/10 * * * * curl --silent http://localhost/gapi/src/test2.php
The URL will depend on how your server is set up - you say it works through your browser at the moment so just use the same URL in the cron 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
* * * * * php /home/admin/public_html/domain.com/public/cron/route.php &>> /home/admin/public_html/domain.com/log/cron.log
I have that cron running every minute.
I want to store the errors that occur in route.php in cron.log
This works wonderfully when I run :
php /home/admin/public_html/domain.com/public/cron/route.php &>> /home/admin/public_html/domain.com/log/cron.log
through the command line manually. But when crontab runs it no errors gets stored in cron.log
the cron.log is owned by admin:admin and the permissions are set to 777 just to be sure.
anyone?
Something like this:
* * * * * /usr/bin/php /home/admin/public_html/domain.com/public/cron/route.php >> /home/admin/public_html/domain.com/log/cron.log 2>&1
Where the standard error is redirected to the same destination as standard output (with 2>&1), this will collect any errors outside of the script and add them to the cron.log file.
This can be simply called with > symbol on cron or php -q or -f command.
On your case
php -q /home/admin/public_html/domain.com/public/cron/route.php > /home/admin/log.txt 2> /dev/null
Blockquote php -q /home/admin/public_html/domain.com/public/cron/route.php > /home/admin/log.txt 2> /dev/null