سؤال

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?

هل كانت مفيدة؟

المحلول

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();
}

نصائح أخرى

I would go with the approach hek2mgl has suggested.

or, if you want to set up a cron job then here is the url you should be using to execute your script on given time:

/usr/bin/php5 /your/directory/path/cron_script.php

To check the path:

Create an index.php in your root folder.

<?php
  var_dump(dirname(__FILE__));
?>

Hope this help.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top