|
Posted by Jerry Stuckle on 06/26/05 23:31
Good Man wrote:
> Hi
>
> I'm building a 'job posting' site of sorts.
>
> When a job is available in a particular state, I want the system to send an
> email to everyone who is 'watching' that state.
>
> I know how to do this, but I need to figure out a way to 'send the emails
> in the background' - ie: if an administrator adds a job to Wyoming, I don't
> want them to have to wait for the php script to finish selecting and e-
> mailing everyone watching the state before the administrator can move on
> and do other things.
>
> I originally thought that passing this task to the PHP command line would
> do the trick, but it turns out that a script like...
>
> exec("my php script that emails people");
> echo "complete!";
>
> ...does not echo "complete!" until the thousands of people have all had
> their info passed to the mail server (a long time).
>
> I suppose that I could get rid of this by just lumping everyone together in
> the Bcc: field of a single e-mail message, but at this point I'd like to
> keep that as a last resort and go with the personalization ("Hi James... a
> job has been posted in Wyoming").
>
> Does anyone have any thoughts as to how I can send the emails without
> preventing the administrator from doing other tasks until the script has
> finished executing?
I've implemented a queue mechanism in the past; it works fine, and you
can control the rate your messages are sent independent of the UI. I
did it all in PHP and MySQL with a cron job to kick off the queue runner
every 15 minutes (sufficient for my purposes).
Later I rewrote the queue runner in C, but didn't have any noticeable
effects. The PHP code for this was so small it really didn't matter much.
The only thing you want to be careful of is that you don't have two
queue runners going at the same time (i.e. one starts before the
previous one finishes). Depending on timing and exactly how you wrote
the code, you could get duplicate emails sent. You can protect it in
the code - but I found it much easier to just check to see if another
copy was running in a startup script and not start the job if there is.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|