Git Product home page Git Product logo

Comments (10)

liebig avatar liebig commented on July 24, 2024

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.

iClosedz avatar iClosedz commented on July 24, 2024

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.

liebig avatar liebig commented on July 24, 2024

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 Cronjob is not a standard request. But don't worry, you can access all Laravel features from the global.php file.

from cron.

iClosedz avatar iClosedz commented on July 24, 2024

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.

liebig avatar liebig commented on July 24, 2024

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.

iClosedz avatar iClosedz commented on July 24, 2024
  • * * * * /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.

liebig avatar liebig commented on July 24, 2024

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.

iClosedz avatar iClosedz commented on July 24, 2024

Oh! I got it. Thank you very much @liebig .

from cron.

liebig avatar liebig commented on July 24, 2024

You are welcome @iClosedz

from cron.

liebig avatar liebig commented on July 24, 2024

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)

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.