Question

I have a user table with date of birth. I need to send them email to wish for their birthday. When i use a php code it only sends them only when i execute that php file. How to trigger that automatically when the next day starts i.e 12:00 AM

And if there are more number of users on same birthday then more email has to be sent. which takes more time to execute the php. what if it takes more than the time allocated for one php file to execute. how to overcome this.

Note: Am running my own server with Ubuntu. Is there any packages i need to install to run the php script exactly when the day starts..?

Was it helpful?

Solution

A cron job is the answer. I use Debian but I guess cron is in the default installation of Ubuntu. In case it isn't, run in the console:

sudo apt-get install cron

If you want some kind of visual assistance you can also install gnome-schedule:

sudo apt-get install gnome-schedule

In order to see how to configure cron you can always check the man pages:

man cron
man crontab

Once everything is set up you should set a cron job to call the PHP file. Here is an explanation on how to use PHP in command line mode

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top