By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,746 Members | 1,928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,746 IT Pros & Developers. It's quick & easy.

multithread a process

P: n/a
Hello,

can i use php to multithread mail() or something similar? in my company
i need to send multiple copies of email to a few hundred ppl affilated
and on my list.

instead of calling mail over and over again i would like to thread this
process.

could someone point me to some documentation or perhaps an example of
where to start with this?

cheers

-jpdr
TTG

Jul 16 '05 #1
Share this Question
Share on Google+
12 Replies


P: n/a
On Mon, 18 Aug 2003 14:22:54 +0000 (UTC) in
<message-id:bh**********@hercules.btinternet.com>
haptiK <ha****@yahoo.com> wrote:
Hello,

can i use php to multithread mail() or something similar? in my
company i need to send multiple copies of email to a few hundred ppl
affilated and on my list.

instead of calling mail over and over again i would like to thread
this process.

could someone point me to some documentation or perhaps an example of
where to start with this?

cheers

-jpdr
TTG

bcc the mails?

Regards,

Ian
--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
Jul 16 '05 #2

P: n/a
hello Ian :)
Thanks for your response.

I'm not completly sure what Bcc does, but i do know it is a Blind Carbon
Copy meaning everyone gets a copy of the email without anyone else
knowing who recieved it.

I would still like to discuss threading the mail process.

any other ideas?

Ian.H [dS] wrote:
On Mon, 18 Aug 2003 14:22:54 +0000 (UTC) in
<message-id:bh**********@hercules.btinternet.com>
haptiK <ha****@yahoo.com> wrote:

Hello,

can i use php to multithread mail() or something similar? in my
company i need to send multiple copies of email to a few hundred ppl
affilated and on my list.

instead of calling mail over and over again i would like to thread
this process.

could someone point me to some documentation or perhaps an example of
where to start with this?

cheers

-jpdr
TTG


bcc the mails?

Regards,

Ian


Jul 16 '05 #3

P: n/a
On Mon, 18 Aug 2003 14:42:38 +0000 (UTC) in
<message-id:bh**********@hercules.btinternet.com>
haptiK <ha****@yahoo.com> wrote:
hello Ian :)
Thanks for your response.

I'm not completly sure what Bcc does, but i do know it is a Blind
Carbon Copy meaning everyone gets a copy of the email without anyone
else knowing who recieved it.

Yup, pretty much you'd set the 'To' header to your own mail address,
then list the others as people to BCC.

This would then just use a single mail() call rather than a looped
version.


I would still like to discuss threading the mail process.

any other ideas?

Fair enough.. but can't offer any advice / ideas on this part.. not
actually thought it in the past tbh.. so I'm at a loss for info there
=)

Regards,

Ian

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
Jul 16 '05 #4

P: n/a
haptiK wrote:

[snip BCC]
How then would this behave if im sending thousands of emails to my users
as opposed to threading the mail process? over all performance?


Far better. It's the mail server doing the work, not the PHP script. This
also means you don't disclose everybody's email address, which isn't a very
nice thing to do to people who don't want to get spammed.
--
Jim Dabell

Jul 16 '05 #5

P: n/a
Hi,

haptiK wrote:
How then would this behave if im sending thousands of emails to my users
as opposed to threading the mail process? over all performance?

thanks again for your response.. im new to the theory of threaded
processes and they sound interesting but if im headed down the wrong
trail with this i appreciate your patience.


Using Bcc, with the Bcc field containing the thousands of addresses,
means the the PHP process only sends one email to your mail server very
quickly. It is then up to the mail server to copy it out to everyone on
the Bcc list. This is also more efficient for the Internet, as if 200
people at example.com need a copy, your mail server will pass 1 copy to
example.com's email server with the 200 recipients listed, and
example.com's mail server will copy that message to all 200 people,
saving a lot of Internet bandwidth.

You couldn't easily use multithreading easily for what you want, as the
PHP process (and so page transfer) won't finish until all the threads
finish (you could possibly make your web server stop the request by
closing the filehandle, but its not guaranteed - your web server might
wait until it can reap the process).

You could use program execution functions (eg fork() and exec() under
Unix, or your OS moral equivilent) to send the messages from another
process and then have the main process return before the other one, but
check you don't end up with zombies.

Most Internet people would prefer you use the 1st method,

Bcc: a@example.com, b@example.net, c@example.org

Because it saves bandwidth, and if two addresses are mapped to the same
account they often won't get duplicates, but it does mean you can't
'personalise' the emails. But it also neatly puts the time-to-send
problem off PHP and on to the mail servers, optimised to do the job :-)

Regards,

Luke

Jul 16 '05 #6

P: n/a
Greetings Mr Ross.

Fantastic argument and I understand completly now why Bcc: is the best
option over trying to thread via php.

Thank you for your timely responses everyone.

- jpdr
TTG

Luke Ross wrote:
Hi,

haptiK wrote:
How then would this behave if im sending thousands of emails to my
users as opposed to threading the mail process? over all performance?

thanks again for your response.. im new to the theory of threaded
processes and they sound interesting but if im headed down the wrong
trail with this i appreciate your patience.

Using Bcc, with the Bcc field containing the thousands of addresses,
means the the PHP process only sends one email to your mail server very
quickly. It is then up to the mail server to copy it out to everyone on
the Bcc list. This is also more efficient for the Internet, as if 200
people at example.com need a copy, your mail server will pass 1 copy to
example.com's email server with the 200 recipients listed, and
example.com's mail server will copy that message to all 200 people,
saving a lot of Internet bandwidth.

You couldn't easily use multithreading easily for what you want, as the
PHP process (and so page transfer) won't finish until all the threads
finish (you could possibly make your web server stop the request by
closing the filehandle, but its not guaranteed - your web server might
wait until it can reap the process).

You could use program execution functions (eg fork() and exec() under
Unix, or your OS moral equivilent) to send the messages from another
process and then have the main process return before the other one, but
check you don't end up with zombies.

Most Internet people would prefer you use the 1st method,

Bcc: a@example.com, b@example.net, c@example.org

Because it saves bandwidth, and if two addresses are mapped to the same
account they often won't get duplicates, but it does mean you can't
'personalise' the emails. But it also neatly puts the time-to-send
problem off PHP and on to the mail servers, optimised to do the job :-)

Regards,

Luke


Jul 16 '05 #7

P: n/a
haptiK wrote:
Thanks for your response, yes actually avoiding spam is a major
intention here.. thank you for your response i will take this into
account.


Oops, sorry, I forgot the context for a second. There's no problem with
sending individual mails from an email disclosure point of view, only when
CCing (instead of BCCing). The rest applies though - you are essentially
just supplying the mail server with the email and a list of addresses,
rather than an individual email for each address.
--
Jim Dabell

Jul 16 '05 #8

P: n/a
On Tue, 19 Aug 2003 19:25:35 +0200 in
<message-id:bh************@news.t-online.com>
Jochen Buennagel <za**@buennagel.com> wrote:
haptiK wrote:
Fantastic argument and I understand completly now why Bcc: is the
best option over trying to thread via php.


There is a (growing) problem with this: A number of email services
(most notably hotmail) have started to classify emails as spam if the
recipient is not in the "To:" or "Cc:" fields.

ZangBunny

Sounds like another good enough reason not to use Hotmail =)

Regards,

Ian

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
Jul 16 '05 #9

P: n/a
Jochen Buennagel wrote:
haptiK wrote:
Fantastic argument and I understand completly now why Bcc: is the best
option over trying to thread via php.


There is a (growing) problem with this: A number of email services (most
notably hotmail) have started to classify emails as spam if the
recipient is not in the "To:" or "Cc:" fields.


Really? That practice would give an amazing amount of false positives.
Basically any legitimate bulk mail. I've just tested it with Hotmail, and,
with the default settings, BCCed email gets through just fine. It may be
that at higher spam filtering settings, it does not get through, but
Hotmail explicitly tells you that you could miss legitimate email with
these settings, so I'd regard that as acceptable loss. After all, if
that's all it takes to get classed as spam, then they must be missing more
than just a few emails from you.
--
Jim Dabell

Jul 16 '05 #10

P: n/a
I know your goal isnt to confuse me on purpose but does bcc pose these
problems or not? should i still be investigating multithreaded email?

:)

- jpdr
TTG

Jim Dabell wrote:
Jochen Buennagel wrote:

haptiK wrote:
Fantastic argument and I understand completly now why Bcc: is the best
option over trying to thread via php.


There is a (growing) problem with this: A number of email services (most
notably hotmail) have started to classify emails as spam if the
recipient is not in the "To:" or "Cc:" fields.

Really? That practice would give an amazing amount of false positives.
Basically any legitimate bulk mail. I've just tested it with Hotmail, and,
with the default settings, BCCed email gets through just fine. It may be
that at higher spam filtering settings, it does not get through, but
Hotmail explicitly tells you that you could miss legitimate email with
these settings, so I'd regard that as acceptable loss. After all, if
that's all it takes to get classed as spam, then they must be missing more
than just a few emails from you.


Jul 16 '05 #11

P: n/a
well this actually brings up something in the requirements list that i
failed to realize yesterday. The subjects of the email are meant to
distinctly identify each email recipient on a personal level. this is of
course to maintain a professionalism when speaking to our customers etc..

i think because of this BCc: is out of the question.

damn. i was really excited about the use of BCc, but i guess its back to
square one and discussing multithreading or spawning new procs with php.

can someone discuss this with me? is it sensible to use system()
passthru() or exec() to pass the job of mailing over to a shell
script... i just dont know where to go with this now...


Luke Ross wrote:
Hi,

haptiK wrote:
I know your goal isnt to confuse me on purpose but does bcc pose these
problems or not? should i still be investigating multithreaded email?

The general consensus is no. My Yahoo webmail is perfectly capable of
receiving them, and other people says hotmail is fine. Some really
really braindead spamfilters might reject them, but then braindead spam
filters can reject anything for any reason so it's not really worth
worrying about it. With any sort of list the odd email will come back as
people change their email address, mess up their filtering, go over
quota, etc.

In the Bcc vs multiple send argument, I'd be guided about whether you
need to send different email content to different people. If you want
the same content to go to lots of people, you probably want to use Bcc.
If you want different email content to go to different people, then your
only choice is multiple send, probably by starting another process.

Hope that clarifies things!

Regards,

Luke


Jul 16 '05 #12

P: n/a
Hi,

haptiK wrote:
well this actually brings up something in the requirements list that i
failed to realize yesterday. The subjects of the email are meant to
distinctly identify each email recipient on a personal level. this is of
course to maintain a professionalism when speaking to our customers etc..
It always amuses me that customers feel more important if the email
starts "Dear [name here]". But it does seem to make a difference to
people, granted.
i think because of this BCc: is out of the question.
Yes.
damn. i was really excited about the use of BCc, but i guess its back to
square one and discussing multithreading or spawning new procs with php.

can someone discuss this with me? is it sensible to use system()
passthru() or exec() to pass the job of mailing over to a shell
script... i just dont know where to go with this now...


As mentioned before, I think you'll find multithreading a) difficult and
b) not very effective. It does depend a little on the OS you're using
though.

I would personally write a script in Perl or something like that to
email everyone, and just have PHP invoke it with something like
system("/bin/bash myscript.pl &"); to background it (assuming you're
using a unix). If you need a PHP solution you could fire off a PHP CGI
executable to do something similar for you. It's a little crude, but by
far the quickest and easiest way to do this I'd have thought.

Luke

Jul 16 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.