Comments (10)
Hi @iClosedz,
your crontab definitions only work if PHP is installed on your server at /usr/bin/php
and your Laravel page is located at /var/www/laravel
. This are only example values so you need to change them. Just test Cron by running the command from the shell. If everything works fine you can find the jobs at your database table cron_job
. Your jobs only run every day at 4 and 5 o'clock, so please add a example job with the expression '* * * * *' for testing. Or you have to wait until it is 4 or 5 o'clock.
from cron.
Thank you for you answer.
If I have example job with the expression '* * * * *' to test.
so my crontab setting must set to * * * * * /usr/bin/php /var/www/laravel/artisan cron:run too ?
and last thing,
How can I call the controller from global.php (I'm new on laravel and MVC = =)
I using php-fpm so how can I find the php path like /usr/bin/php
Thank you verymuch @liebig you create the best thing for us to handle the cronjob.
from cron.
Thank you for your feedback @iClosedz. Please check if PHP is callable at /usr/bin/php
and change this value if PHP is installed at a different location. And please check if your Laravel page is located at /var/www/laravel/
and change this value if your Laravel
page is installed at a different location. The crontab command * * * * * /usr/bin/php /var/www/laravel/artisan cron:run
is only an example. You have to check where your PHP and Laravel homepage is located. I don't know php-fpm
so please ask your hoster for this information.
You can't call a controller from Cron. A controller is used to handle a request and return the response. A Cron
job is not a standard request. But don't worry, you can access all Laravel
features from the global.php
file.
from cron.
yes I understand * * * * * /usr/bin/php /var/www/laravel/artisan cron:run is an example
but I want to make sure that if I use Cron::add so I need to set crontab right ?
from cron.
I don't understand your comment. You need crontab to start Cron
. Please have a look at the readme.
Do I really need crontab or an online cronjob service
Yes, you do. In comparison to a Java application server for example, PHP only runs if it is executed. If crontab or an online cronjob service provider calls PHP and starts the application, Cron can execute the jobs and will start the work. If PHP is not started, the application sleeps and nothing happens.
from cron.
- * * * * /usr/bin/php /var/www/laravel/artisan cron:run Is use to start Cron
and why Cron::add is need to add the time 'example1', '* * * * *' ?
Is this duplicate ?
from cron.
Dude, please read my comment again. You need a request or command call to start Cron
. PHP is only running if you execute it. And that does the crontab job * * * * /usr/bin/php /var/www/laravel/artisan cron:run
. Now you have to add all your PHP jobs with the Cron::add
function. There is a little overhead, because you add the expression * * * * *
twice. But if you have a job who is running every minute and a job which only needs to be executed every five minutes, you need crontab to call Cron
every minute. If you are searching for the best crontab interval, please have a look at the readme.
What is the best interval to call the route or command?
The best interval depends on your jobs. If one job should be executed every minute and another every five minutes, the route or command has to be called every minute. In general you have to find the greatest common divisor of your jobs. Please don't forget to change the runInterval
config value if the route or command is not called every minute (default value) and if you want to use Cron's in time check.
from cron.
Oh! I got it. Thank you very much @liebig .
from cron.
You are welcome @iClosedz
from cron.
This issue is closed for a while, but I have to correct me:
You can call a controller method from Cron with App::make('App\Http\Controllers\YourController')->method();
. I am sorry for my mistake.
from cron.
Related Issues (20)
- Are tests working? HOT 2
- Incompatibility with Laravel 8, 9 HOT 1
- Exception with two closures on the same line of code HOT 3
- Symfony\Component\Console\Helper\HelperSet->get('table') HOT 3
- usage question: loading jobs from database HOT 3
- command cron:run/list error HOT 1
- stop cronjob run during beforeRun event HOT 3
- Cron job running only one time HOT 3
- Pull request #80 not in composer package HOT 3
- trying to understand why I should use this over Laravel's built-in scheduler HOT 2
- Which user should run cron HOT 2
- Laravel 5.4 support HOT 3
- PHP Fatal error: Class 'App\Providers\Cron' not found in C:\xampp\htdocs\isend\blog\app\Providers\AppServiceProvider.php on line 33 HOT 3
- laravel5.2.45 install failed HOT 2
- passing variable to the function parameter before adding a cron HOT 5
- Have Undefined index while run the cron job!!! HOT 3
- Php artisan cron:run Not working HOT 13
- Can't use `artisan route:cache` because the built-in cron route uses a closure HOT 5
- [Laravel 5.6] Ambiguous class resolution warning HOT 10
- doesn't work with Laravel 5.8 HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cron.