Web Hosting Talk







View Full Version : php, mail, and forking


Adam Hallett
06-07-2007, 02:40 PM
I'm using the pthrads library and I would like to create maybe 100 different processes to send mail(). But I'm not sure how to write the application based on the problems of race conditions and shared memory.

stdunbar
06-07-2007, 03:01 PM
I'm not really following what you want to do. You mention threads and processes - what do you intend to do?

If you created a C/C++ threaded application and want to fire that off from PHP then that would be fine. If you want to start a bunch of processes from PHP that is sorta ok too though you'd need to be very careful in doing so. And what are you doing with shared memory?

Can you fill us in a bit more?

Adam Hallett
06-07-2007, 03:49 PM
I have a list of email addresses that I need to send mail to. So I want to have 100 php threads executing the mail() command continuously. So yes, the forking is using php's pthread capabilities.

mwatkins
06-07-2007, 04:11 PM
forking != multiple threads of execution.
forking == multiple processes.

WO-Jacob
06-07-2007, 05:04 PM
I have a list of email addresses that I need to send mail to. So I want to have 100 php threads executing the mail() command continuously. So yes, the forking is using php's pthread capabilities.

You're likely able to overload your mailserver with just a single php process sending email. PHP, once it's runnning, runs pretty gosh darn quick. Doing the same thing in multiple threads is likely to make things slower rather than faster, and as you're looking at, much more complicated as well. :)

Adam Hallett
06-07-2007, 05:07 PM
You're likely able to overload your mailserver with just a single php process sending email. PHP, once it's runnning, runs pretty gosh darn quick. Doing the same thing in multiple threads is likely to make things slower rather than faster, and as you're looking at, much more complicated as well. :)

sendmail() is slow

01globalnet
06-07-2007, 06:40 PM
Have you looked at this class?

http://www.swiftmailer.org

It has some great features (batch sending, caching etc).

hsncool
06-09-2007, 08:37 AM
whats rong withh just looping the mail() command?

...eg....
------------------------------------------
$email[1] = 'a@a.com' ('a@a.com');
$email[2] = 'b@b.com';
// ...etc

while(x < len($email)) {
mail($email[$x],'hi!',...etc...);
++$x;
}
--------------------------------------

whats wrong with that? have i missread what you wanted to do?

Angelo
06-09-2007, 10:18 AM
You must compile php with process control functions support (pcntl). There are some functions within this library. pcntl_fork() (http://www.php.net/pcntl_fork) for instance. Its not the best practice to do this in PHP, but we use it for some of our shell applications and it works fast/nice.