multithread a process

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • haptiK

    multithread a process

    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

  • Ian.H [dS]

    #2
    Re: multithread a process

    On Mon, 18 Aug 2003 14:22:54 +0000 (UTC) in
    <message-id:bhqnfu$92k$1 @hercules.btint ernet.com>
    haptiK <haptiK@yahoo.c om> wrote:
    [color=blue]
    > 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
    >[/color]


    bcc the mails?



    Regards,

    Ian


    --
    Ian.H [Design & Development]
    digiServ Network - Web solutions
    www.digiserv.net | irc.digiserv.ne t | forum.digiserv. net
    Programming, Web design, development & hosting.

    Comment

    • haptiK

      #3
      Re: multithread a process

      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:
      [color=blue]
      > On Mon, 18 Aug 2003 14:22:54 +0000 (UTC) in
      > <message-id:bhqnfu$92k$1 @hercules.btint ernet.com>
      > haptiK <haptiK@yahoo.c om> wrote:
      >
      >[color=green]
      >>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
      >>[/color]
      >
      >
      >
      > bcc the mails?
      >
      >
      >
      > Regards,
      >
      > Ian
      >
      >[/color]

      Comment

      • Ian.H [dS]

        #4
        Re: multithread a process

        On Mon, 18 Aug 2003 14:42:38 +0000 (UTC) in
        <message-id:bhqoku$c3e$1 @hercules.btint ernet.com>
        haptiK <haptiK@yahoo.c om> wrote:
        [color=blue]
        > 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.[/color]


        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.

        [color=blue]
        >
        > I would still like to discuss threading the mail process.
        >
        > any other ideas?[/color]


        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.ne t | forum.digiserv. net
        Programming, Web design, development & hosting.

        Comment

        • Jim Dabell

          #5
          Re: multithread a process

          haptiK wrote:

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

          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

          Comment

          • Luke Ross

            #6
            Re: multithread a process

            Hi,

            haptiK wrote:[color=blue]
            > 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.[/color]

            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

            Comment

            • haptiK

              #7
              Re: multithread a process

              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:
              [color=blue]
              > Hi,
              >
              > haptiK wrote:
              >[color=green]
              >> 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.[/color]
              >
              >
              > 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
              >[/color]

              Comment

              • Jim Dabell

                #8
                Re: multithread a process

                haptiK wrote:
                [color=blue]
                > Thanks for your response, yes actually avoiding spam is a major
                > intention here.. thank you for your response i will take this into
                > account.[/color]

                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

                Comment

                • Ian.H [dS]

                  #9
                  Re: multithread a process

                  On Tue, 19 Aug 2003 19:25:35 +0200 in
                  <message-id:bhr2c7$fi$07 $2@news.t-online.com>
                  Jochen Buennagel <zang@buennagel .com> wrote:
                  [color=blue]
                  > haptiK wrote:[color=green]
                  > > Fantastic argument and I understand completly now why Bcc: is the
                  > > best option over trying to thread via php.[/color]
                  >
                  > 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
                  >[/color]


                  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.ne t | forum.digiserv. net
                  Programming, Web design, development & hosting.

                  Comment

                  • Jim Dabell

                    #10
                    Re: multithread a process

                    Jochen Buennagel wrote:
                    [color=blue]
                    > haptiK wrote:[color=green]
                    >> Fantastic argument and I understand completly now why Bcc: is the best
                    >> option over trying to thread via php.[/color]
                    >
                    > 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.[/color]

                    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

                    Comment

                    • haptiK

                      #11
                      Re: multithread a process

                      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:[color=blue]
                      > Jochen Buennagel wrote:
                      >
                      >[color=green]
                      >>haptiK wrote:
                      >>[color=darkred]
                      >>>Fantastic argument and I understand completly now why Bcc: is the best
                      >>>option over trying to thread via php.[/color]
                      >>
                      >>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.[/color]
                      >
                      >
                      > 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.
                      >
                      >[/color]

                      Comment

                      • haptiK

                        #12
                        Re: multithread a process

                        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:
                        [color=blue]
                        > Hi,
                        >
                        > haptiK wrote:
                        >[color=green]
                        >> 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?[/color]
                        >
                        >
                        > 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
                        >[/color]

                        Comment

                        • Luke Ross

                          #13
                          Re: multithread a process

                          Hi,

                          haptiK wrote:[color=blue]
                          > 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..[/color]

                          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.
                          [color=blue]
                          > i think because of this BCc: is out of the question.[/color]

                          Yes.
                          [color=blue]
                          > 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...[/color]

                          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

                          Comment

                          Working...