Comments (8)
Hi mrlonely90,
Thanks for using Cron. You now need something which run Cron
every minute. This can be the console with crontab and the command php artisan cron:run
or you can use a route. Please have a look at the README.
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.
Best Regards,
Marc
from cron.
If I want to create a cron with a route. I read the document and issues but not clearly.
Can use help to do it step by step? Please help me.
- Create a cronjob function in file global.php
Event::listen('cron.collectJobs', function() {
Cron::add('test', '* * * * *', function() {
// code to do something
});
});
2 . I don't know what to do
How to create a function or something to config cronKey and run url http://yourdomain.com/cron.php?key=securitykey
Which file must I write code?
Need to write something to file routes.php ?
And when i run by cmd php artisan cron:run
It always return Errors column 1 but everything working good.
Thanks a lots!
from cron.
After creating the Cron
function you have to config a secret key for the route you want to call. You can run the command php artisan cron:keygen
and save this generated key to the config file at the key cronKey
. After that you need to config an online cron service provider (like setcronjob.com or easycron.com) to call this route every minute.
From the README:
If you don't have shell access to your server, you can easily use an online cronjob service (Google knows some good provider). This provider will run Cron's route in a defined interval. The Cron route has to be protected because if someone else than the service provider invokes it, our jobs will be executed too often. For that reason we need a security key in addition to the route path. This key can be generated with the "php artisan cron:keygen" command call and has to be set in the Cron config file at the key cronKey.
// Cron application key for securing the integrated Cron run route - if the value is empty, the route is disabled
'cronKey' => '1PBgabAXdoLTy3JDyi0xRpTR2qNrkkQy'
Now you have to configure the address and run interval at your online cronjob service provider. The address for the integrated Cron route is always "http://yourdomain.com/cron.php?key=securitykey". For the above example this address could be "http://exampledomain.com/cron.php?key=1PBgabAXdoLTy3JDyi0xRpTR2qNrkkQy" and the run interval has to be every minute (due to the job with the name "example1"). Now the jobs were added, the route key was generated and the service provider was configured.
from cron.
Thanks so much!
You forgot answer me the second question.
And when I run by cmd php artisan cron:run
It always return Errors column 1 but everything working good.
Event::listen('cron.collectJobs', function() {
Cron::add('test', '* * * * *', function() {
return 'Code working good';
});
});
I dont't know why it return Errors column 1. Please help me again.
from cron.
You always get an error, if you return anything. If everything was fine, don't return anything (or return null). From the README:
The given anonymous function will be invoked if the expression details match with the current timestamp. This function should return null in the case of success or anything else if there was an error while executing this job.
from cron.
Thanks, I understand that errors now.
I have a ubuntu linux server and I can access my server by using ssh.
All I need to do is run cmd php artisan cron:run
and the server will auto run cron every minute, isn't it?
And I don't need to do anything more.
from cron.
From 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.
So it is not enough to run the cmd command php artisan cron:run
once, you need to call it every minute. On Linux you can use crontab for this, on a server without shell access you can use the Cron
route.
from cron.
Yes, now I see. Thank you so much.
Best wishes for you!
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.