views:

155

answers:

4

I am new to web programming, and I am developing a simple appointment app with PHP + MySQL. Is there a simple way to add a background process on a timer (to send out daily appointment reminders, for example)? This could be done easily in another language, but I want it to run on shared hosting with only PHP.

+5  A: 

Your host may or may not approve of this. You can write a PHP script for use on the command line and make a crontab entry to run it periodically. If you don't have command-line access to the PHP interpreter, you could write the script to run in the web server and hit it with wget or curl, also using a crontab entry.

Matt Kane
+1 for using cron on a local machine + public-facing script on the remote machine. Remote-cron is a cool idea.
tj111
+1  A: 

This has been discussed on Stack Overflow here and here before—check it out!

0scar
Of course, I never think to check for duplicates before writing an answer!
Matt Kane
A: 

If you have a Linux webhost, you might be able to use a cronjob (to automatically run a script periodically)--even on shared hosting. Some webhosts with shared web hosting allow you to create cronjobs via cPanel (or whatever they use).

That would really be your best bet, as opposed to creating a background process on the server, which the webhost probably would not be very kind about. So definitely check and see if you can use cron.

DashRantic
A: 

I work in a place where I cannot set a cron job so I made a page that when viewed it checks the time since the last time it did a list of jobs. If the time since job last run is over a set threshold it runs the list of jobs. Then I set up a scheduled job on a computer that I know is on all the time and connected to the internet and would open the page every 10 minutes. Worked pretty constantly. Got the idea from Joel on a stack overflow podcast episode.

tvanover