473,382 Members | 1,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Sending Lots of Emails in the BACKGROUND?

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?
Jul 17 '05 #1
8 6477
*** Good Man wrote/escribió (Thu, 23 Jun 2005 00:03:14 -0500):
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?


Do you have access to a crontab facility? Writing a shell script* that
sends needed mails and configuring it to execute at regular intervals can
be a good option.

(*) Shell scripts can be written in PHP too.

--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #2
Good Man <he***@letsgo.com> wrote:
[snip]
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). [snip] 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?

[snip]

You need to fork and background that process (see
http://nl2.php.net/manual/en/function.pcntl-fork.php or simply append a
'&' to the program/script you exec (making sure _any_ output is
redirected to eg /dev/null)).

Better yet would be to create a que mechanism, add email and body to a
database and have a script periodically check if there are entries to be
sent. That way there is only 1 process trying to spam^Wsend email you
have to look after.

Jul 17 '05 #3
Alvaro G Vicario <al******************@telecomputeronline.com> wrote in
news:zd****************************@40tude.net:
*** Good Man wrote/escribió (Thu, 23 Jun 2005 00:03:14 -0500):
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?


Do you have access to a crontab facility? Writing a shell script* that
sends needed mails and configuring it to execute at regular intervals
can be a good option.

(*) Shell scripts can be written in PHP too.


i don't want to do a crontab, because ideally i'd like 'instant'
notification when a job is posted... but i suppose an hourly crontab might
not be TERRIBLE...
Jul 17 '05 #4
Daniel Tryba <pa**********@invalid.tryba.nl> wrote in
news:42***********************@news6.xs4all.nl:
Good Man <he***@letsgo.com> wrote:
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?

[snip]
Better yet would be to create a que mechanism, add email and body to a
database and have a script periodically check if there are entries to
be sent. That way there is only 1 process trying to spam^Wsend email
you have to look after.


you clever devil, thanks for the suggestion!
Jul 17 '05 #5
*** Good Man wrote/escribió (Thu, 23 Jun 2005 08:37:28 -0500):
i don't want to do a crontab, because ideally i'd like 'instant'
notification when a job is posted... but i suppose an hourly crontab might
not be TERRIBLE...


Or even a Once Every Fifteen Minutes if necessary, given the script is
designed to cause little load if no work left and to stand ocasional
overlappings.
--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Jul 17 '05 #6
GM,

I assume you're using Linux here, right? It works much better that way
for this kind of thing. The way I do it is to have my PHP fork off
another PHP page to do the work. In my case, I have a work order
ticketing system. I don't want to hold up the user while the mail
server is busy, so I fork off a process in RAM and then return the user
immediately back with a message that the email will be sent to the user
shortly. On my web server in a given day, you may see a couple dozen of
these forked files in RAM, waiting for the slow mail server in our
corporate intranet to respond over the T1 connection. The queue
mechanism is better because of error control, but my mechanism is the
poor man's version. You can build the queue with a database and a cron
job that calls the PHP page to read the database, send the email, and
go back to sleep again until the next cron wakeup time. Your task,
then, would be to only file these entries in the database.

Jul 17 '05 #7
Q: How can I send bulk mails with PHP?
A: PHP may not be the right choice for sending bulk mails. PHP's
built-in mail() function is written to use sendmail binary; and higher
performance is not usually expected. It is also suggested that qmail is
faster than sendmail; to make PHP to use qmail instead of sendmail, one
has to work on the make and installation process. There are many (C
based) applications available to speed up sendmail.

Another suggestion is to sort the email addresses based on domain names
and deliver them using BCC. Most of the time, this will make the mail
to be delivered in junk folder as many spam guards trap BCCed mails.

Many commercial bulk mailers such as LISTSERV guarantee high speed
delivery as they seem to use higher-end hardwares and resources.

Refer:
1. http://www.php.net/mail
2. ftp://cs.utk.edu/pub/moore/bulk_mail..._mailer.README

+++++
@todo Grammar cleanup.

Jul 17 '05 #8
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.
js*******@attglobal.net
==================
Jul 17 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dan glenn | last post by:
I'm creating HTML emails from a PHP site and sending them out to an email list (just about 40 people so far are on this list). I've tested and confirmed that these emails work in yahoo.com's...
10
by: Stuart Mueller | last post by:
I have an exchange server, that I sometimes use to perform mail shots to clients on our database, these can be upwards of 1000 at a time. As we don't want different clients to see who we are...
3
by: martin smith | last post by:
Here's the scenario. I'm currently using cdosys/asp to send mail to our SMTP server. We use a product called MailFilter to check for SPAM. It doesn't work very well. If MailFilter isn't working...
2
by: Mr. x | last post by:
Hello, I am sending emails with Hebrew contents. When receiving emails - I cannot see the Hebrew characters (it is not outlook express configuration, because when receiving emails from friends -...
7
by: Lau | last post by:
I need to send 1000 emails from an asp.net website. Normally I would use System.Web.Mail.MailMessage() to send thru an SMTP server. But the large amount of emails results in a timeout. My server...
3
by: A | last post by:
Hi all! I would like to ask a question on sending emails... I have a web application that requires sending emails using email templates. The templates that I've made are separate HTML files...
3
by: Ant | last post by:
Hi, I'm using the MailMessage & smtpMail classes in System.Web.Mail to send mail, however it's not sending any emails. I'm using it on a Windows 2003 server. The simplest way to use this is...
5
by: Kun | last post by:
i have the following code: ---------------------------------- import smtplib from email.MIMEText import MIMEText fp = open('confirmation.txt', 'rb') msg = MIMEText(fp.read()) From =...
1
by: robbiesmith79 | last post by:
Just so this is out there on the web, I battled the past 24 hours about this. Background info... I developed a ecommerce website in PHP 4 on a shared linux hosting plan from GoDaddy and had the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.