How to set an alarm using PHP
What about if I want to make weekly notification, that rises an alarm once in every week, month, year, or any cycling period of time? And what about if I don’t want to assign CRON jobs to do that kind of work or I don’t want to update my CRON jobs periodically? May be you are a guest for a free web host. Occasionally, small amount of free hosts do offer cronjobs but they don’t offer both CRONjobs and shell access together. The worse they support cronjobs but they don’t allow you to schedule tasks using it. Frankly, CRON jobs is for the giants.
In PHP, you can do whatever you want. You can write down script to wake you up, another script to e-mail you notifying something like birthdays or to-do tasks, let me say PHP is a rich programming language that offers everything in the web programming life.
A friend of me suggested placing a banner on his website, which executes a weekly ad for a community radio show. The script below wakes up once in every week, it first checks the day, then the time, if it is the exact time to wakeup it displays a message, let me say an image banner or something like that, when it reaches the end time it goes back to sleep, or simply it displays something else like next time schedule.
The script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | <?php // The timezone for the event date_default_timezone_set('Africa/Mogadishu'); // Set the day for the event if(date("l") == "Monday"){ // The script checks if it’s the exact time for the event if(date("g") >= "10" && date("g") <= "11" && date("a") == "pm"){ //It’s the exact time, show the banner echo "Today is Monday, and its between 10 - 11 PM"; } else{ // Today is Monday but it’s not time to wake up. echo "Today is Monday, but it's not between 10 - 11 PM"; } } else{ // Today is not Monday, wait till the next Monday. echo "Today is not Monday"; } ?> |
Note: You can find a bundle of PHP supported timezones on PHP website: Click Here.
Hmmm… It’s easy, huh? You can place this script on everywhere on your website to assign notifications like when you’ll become online for live-help, when it’s the time for live-help a clickable banner displays showing something like: “Hello folks, I’m online now”. Or just you can apply this for concerts, etc…
Popularity: 17% [?]


Leave a Reply