|
Posted by C. on 08/02/07 11:40
On 1 Aug, 17:38, "Dave Mennenoh" <d...@blurredistinction.com> (Head
Developer AND Adobe Community Expert) wrote:
> Is there a way with PHP to send out a timed, email reminder? For instance,
> to send a client an email that their subscription will be expiring in a
> week - or to send an email a day before an appointment is due. I can see how
> to do if someone logs in and then I run a appointment checker script - but
> how to do as a service, or daemon, so it works anytime?
>
Like the other guys said, cron is the prefered way to do this. And you
should implement it is as CLI PHP parsed script outside the webserver
document root.
If this is not possible becuase you've got a really cheap hosting
service you could tie it to your web requests in a common include:
<?php
if (rand(80)>75) { // tune according to your traffic levels/required
granularity
if (filemtime($path_to_touch_file) && !file_exists($lockfile)) {
file_put_contents($lockfile, getmypid());
$qry="SELECT * FROM scheduled_jobs WHERE due<=NOW()";
// (of course you don't need to store the jobs in a database)
....
$qry="UPDATE scheduled_jobs SET due=due+repeat_interval WHERE id=
$job_id";
....
unlink($lockfile);
file_put_contents($path_to_touch, getmypid());
}
}
?>
HTH
C.
Navigation:
[Reply to this message]
|