The idea of cron and scheudled seems to contradict what you are actually trying to do. If you want something to be displayed (iframe in this case) only at certain points in time, you can simply check the server time during each request and select it if you are for a certain period of time.
Something like this will produce the same effect as the cron job, with more granularity, checking the time at the moment requst is required.
<?php $hour = date('G'); <iframe .... ></iframe> <?php } ?>
You can expand the conditional statement to show the iframe several times a day, or try a script to check which external condition you want to use to control the display of your iframe.
Update: Additional times or types of comparisons can be specified using
<?php $hour = date('G'); $day = date('N'); // 1..7 for Monday to Sunday if (($hour >= 5 && $hour <= 7) // 5am - 7am || ($hour >= 10 && $hour <= 12) // 10am - 12 noon || ($hour >= 15 && $hour <= 19) // 3pm - 7pm || ($day == 5) // Friday ) { ?> <iframe...></iframe> <?php } ?>
The idea of periodically adding / removing an iframe from under your header with a server / task-side scheduler job is much more complicated than just conditionally displaying it during each request.
Even if you have a specific task that needs to be performed, for example, a periodically generated report, the actual work of displaying the results is usually independent of the periodic task. The PHP script is responsible for showing that the iframe will still query the database at the time of the request for any new content that will be displayed, and display it if it is found, and not a periodic task, modifying the script in some way to include the iframe .
meagar
source share