Git Product home page Git Product logo

Comments (8)

liebig avatar liebig commented on July 24, 2024

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.

mrlonely90 avatar mrlonely90 commented on July 24, 2024

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.

  1. 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.

liebig avatar liebig commented on July 24, 2024

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.

mrlonely90 avatar mrlonely90 commented on July 24, 2024

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.

liebig avatar liebig commented on July 24, 2024

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.

mrlonely90 avatar mrlonely90 commented on July 24, 2024

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.

liebig avatar liebig commented on July 24, 2024

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.

mrlonely90 avatar mrlonely90 commented on July 24, 2024

Yes, now I see. Thank you so much.
Best wishes for you!

from cron.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.