CGI vs PHP mailer

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Spaceman-Spiff
Forum Newbie
Posts: 8
Joined: Wed Nov 06, 2002 2:46 am

CGI vs PHP mailer

Post by Spaceman-Spiff »

I have a newsletter script running in my website, sending 1500 emails every week, it's currently using php mail() function, but it's very slow. I've tried both sendmail and SMTP, and both has the same speed.
I read somewhere that a CGI Mailer will be faster than a php script. Is this true? Or is my webhost mail server just slow?
What are the advantages using a CGI mail script instead of PHP? or vise versa
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Most likely is just a slow mail mailserver.

Are you sending each message individually, or in batches in cc/bcc fields? I would suspect the latter might speed things up a little if you weren't already doing that.
Spaceman-Spiff
Forum Newbie
Posts: 8
Joined: Wed Nov 06, 2002 2:46 am

Post by Spaceman-Spiff »

No CCs and BCCs
I currently make the script sends 25 mails, rests for 4 secs, then send another 25, until all are sent.
It takes about 5-30 seconds to send 25 mails :(

since i read that site above, i'm thinking to use a CGI script instead, if it is faster. but i dont know much about CGI to know if its true or not
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

I doubt that CGI will be faster. (How is your PHP installed as an apache module or as regular CGI gateway? If the latter then you'll see no change. And the former is almost always faster anyways.....)

If its possible to do cc's or bcc's that will be faster as its fewer calls to the mail function.
Spaceman-Spiff
Forum Newbie
Posts: 8
Joined: Wed Nov 06, 2002 2:46 am

Post by Spaceman-Spiff »

thx for answer, nielsene
i'll try using cc

the host is verio, the email server is separated from the webserver (external)
i dont know how php is run there, they seem to hide apache part in phpinfo, so i cant check the loaded modules, but under Server API it says: CGI
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

OK then yes your webhost is running the cgi version of PHP, which is almost always slower than the webmodule version.

So unless you planned to rewrite your application in C and compile it for CGI then I don't think changing from PHP to cgi will see ANY improvement.
Spaceman-Spiff
Forum Newbie
Posts: 8
Joined: Wed Nov 06, 2002 2:46 am

Post by Spaceman-Spiff »

thanks again for the answer :)

i'll just stay with php for now
it takes about 15 minutes to send out a newsletter
but we only need to do it once a week
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

I've used Verio before for an online shop - seemed pretty good. I'd be surprised if server speed was an issue, which leaves the efficiency of the particular script you're using - as nielsene has suggested.

You might find a script timer function useful to investigate:

Code: Select all

<?php
function getmicrotime(){
    list($usec, $sec) = explode(" ",microtime());
    return ((float)$usec + (float)$sec);
}
?>
Post Reply