Search code examples
phpcroncron-task

What is correct for auto schedulling of a job using PHP


I have an application written in PHP and MySQL. There I need to activate calendar on a specific and again deactivate that calendar on other specified date. This process will occurs once in a year gap between 2 dates is approx 1.5 months.

how should I do this in PHP? Should I use cron jobs?


Solution

  • Having your requirements, I think it would be more stable to add the check "should I show the calendar" into the source code itself. When the check is well written, it should not consume measurable response time.

    Having the cron job, you always will have to look at an additional thing. This could be forgotton or whatever. Have experienced that too often ;)

    Example for a code that checks that:

    $now = new DateTime();
    if($now >= new DateTime('14 Mar') && $now < new DateTime('15 May')) {
        show_calendar();
    }