rtadams89 Posted December 11, 2008 Share Posted December 11, 2008 I'm hosting my site on a shared Linux hosting package at 1&1. I'm using the following code as part of a larger project to email all my users when a new event gets added to my site's calendar. The $recipients variable is a comma separated string of about 90 email addresses. //Email members on addition of new event. $sql2 = "SELECT * FROM phpbb_users WHERE user_id = ".$uid.""; $result2 = mysql_query($sql2) or die(mysql_error()); $row2 = mysql_fetch_assoc($result2); $name = preg_replace('/(\w+)([A-Z])/U', '\\1.\\2', $row2['username'], 1); $name = explode(".", $name, 2); $name = $name[0] . " " . $name[1]; $recipients = calendar_mail(); $subject = 'New ASURFC Event'; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From: ASURFC <[email protected]>' . "\r\n"; $message = ' <html> <head> <title>New ASURFC Event</title> </head> <body> <p>A new event has been posted on the <a href="http://www.asurfc.com/schedule.php">ASURFC.com calendar</a>.</p> <br>Event Title: '.$title.' <br>Event Date: '.$month . "/" . $day . "/" . $year.' <br>Added by: '.$name.' <br>Event Details: '.$text.' <br><br>If you want to stop receiving notices when new events are added, you can change your notification preferences here: <a href="http://www.asurfc.com/user_cp.php">http://www.asurfc.com/user_cp.php</a>. </body> </html> '; mail($recipients, $subject, $message, $headers); When this code is run, it takes about a minute to complete. It does work, it just takes sooooooooooooo long. I'm worried that as I add more recipients, I will begin to experience errors dues to PHP's max execution time. Should the mail() function be this slow? Is there any way to make it faster? Link to comment https://forums.phpfreaks.com/topic/136585-solved-mail-command-takes-a-long-time-to-finish/ Share on other sites More sharing options...
trq Posted December 11, 2008 Share Posted December 11, 2008 Firstly, do you really want to give out all your users addresses to each user? Bad practice IMO. And yeah, sending mail can take some time. Its not php's mail function thats the problem, but the actual mail server itself. Id usually write a shell script to do this, then execute it via at. Do you have shell access to the server? Link to comment https://forums.phpfreaks.com/topic/136585-solved-mail-command-takes-a-long-time-to-finish/#findComment-713078 Share on other sites More sharing options...
Brian W Posted December 11, 2008 Share Posted December 11, 2008 if you have access to the mail server, be sure that it isn't trying to filter spam and check for viruses on mail sent from you server (since you know/hope that you won't be sending either). That can dramatically slow it down for each address you are sending to. Link to comment https://forums.phpfreaks.com/topic/136585-solved-mail-command-takes-a-long-time-to-finish/#findComment-713083 Share on other sites More sharing options...
rtadams89 Posted December 11, 2008 Author Share Posted December 11, 2008 I'm not to worried about everyone seeing the other user's emails. We are a small organization, and all the members already have access to each other's emails. Unfortunately I do not have shell access. This is one of 1&1's $4/month linux hosting packages. My concern is not with how long it takes for the emails to be sent, but with the delay it introduces in loading the page. Would it be faster to have 5 mail() commands, watch with only 1/5 the recipients? Could I somehow have the mail() command happen in the background so as to not hold up the rest of the script? Link to comment https://forums.phpfreaks.com/topic/136585-solved-mail-command-takes-a-long-time-to-finish/#findComment-713098 Share on other sites More sharing options...
trq Posted December 11, 2008 Share Posted December 11, 2008 Would it be faster to have 5 mail() commands, watch with only 1/5 the recipients? Nope, they all still need to execute. Could I somehow have the mail() command happen in the background so as to not hold up the rest of the script? Not without shell access. Link to comment https://forums.phpfreaks.com/topic/136585-solved-mail-command-takes-a-long-time-to-finish/#findComment-713107 Share on other sites More sharing options...
PFMaBiSmAd Posted December 11, 2008 Share Posted December 11, 2008 The available information is that they will limit you to 99 To: address in one connection to the mail server. So, you will eventually need to break it up into smaller chunks. Link to comment https://forums.phpfreaks.com/topic/136585-solved-mail-command-takes-a-long-time-to-finish/#findComment-713119 Share on other sites More sharing options...
Brian W Posted December 11, 2008 Share Posted December 11, 2008 I have 1&1 too, same package too. mail does run a little slow on because they are trying to prevent mass mailing/spamming from their servers. The available information is that they will limit you to 99 To: address in one connection to the mail server. So, you will eventually need to break it up into smaller chunks. We are a small organization Link to comment https://forums.phpfreaks.com/topic/136585-solved-mail-command-takes-a-long-time-to-finish/#findComment-713121 Share on other sites More sharing options...
trq Posted December 11, 2008 Share Posted December 11, 2008 I have 1&1 too, same package too. mail does run a little slow on because they are trying to prevent mass mailing/spamming from their servers. The available information is that they will limit you to 99 To: address in one connection to the mail server. So, you will eventually need to break it up into smaller chunks. We are a small organization Plus they probably have like a million clients all squished onto a tiny server Link to comment https://forums.phpfreaks.com/topic/136585-solved-mail-command-takes-a-long-time-to-finish/#findComment-713126 Share on other sites More sharing options...
Brian W Posted December 11, 2008 Share Posted December 11, 2008 I have 1&1 too, same package too. mail does run a little slow on because they are trying to prevent mass mailing/spamming from their servers. The available information is that they will limit you to 99 To: address in one connection to the mail server. So, you will eventually need to break it up into smaller chunks. We are a small organization Plus they probably have like a million clients all squished onto a tiny server $4 a month... MILLIONS. Link to comment https://forums.phpfreaks.com/topic/136585-solved-mail-command-takes-a-long-time-to-finish/#findComment-713128 Share on other sites More sharing options...
rtadams89 Posted December 11, 2008 Author Share Posted December 11, 2008 So will breaking it into multiple mail() commands that are run in series make it faster? Link to comment https://forums.phpfreaks.com/topic/136585-solved-mail-command-takes-a-long-time-to-finish/#findComment-713129 Share on other sites More sharing options...
Brian W Posted December 11, 2008 Share Posted December 11, 2008 no, not that I know of. If anything it would make it slower because you'd have to re-establish connection to mail server. like I said, the slowdown isn't you coding, its the server. upgrade packages or completely go away from 1&1. Link to comment https://forums.phpfreaks.com/topic/136585-solved-mail-command-takes-a-long-time-to-finish/#findComment-713141 Share on other sites More sharing options...
rtadams89 Posted December 11, 2008 Author Share Posted December 11, 2008 Is there a nice way to allow who ever is submitting the new calendar event to know what is going on. Otherwise I'm afraid they will think the browser windows is frozen and close it. Link to comment https://forums.phpfreaks.com/topic/136585-solved-mail-command-takes-a-long-time-to-finish/#findComment-713147 Share on other sites More sharing options...
Brian W Posted December 11, 2008 Share Posted December 11, 2008 next to whatever they click (submit button?) make a comment that it may take up to a minute to finish updating and ask them not to do anything till it is done. Link to comment https://forums.phpfreaks.com/topic/136585-solved-mail-command-takes-a-long-time-to-finish/#findComment-713151 Share on other sites More sharing options...
ashton321 Posted December 11, 2008 Share Posted December 11, 2008 I read something about the PEAR library having a better mail function. Would that help? Link to comment https://forums.phpfreaks.com/topic/136585-solved-mail-command-takes-a-long-time-to-finish/#findComment-713181 Share on other sites More sharing options...
Brian W Posted December 11, 2008 Share Posted December 11, 2008 not that I know of. PEAR is a library that must be on the server. I do not believe 1&1 has that library since their Linux server is mostly neglected by them. PEAR's strengths include allowing you to pass mail server credentials in the PEAR mail function. Again, move servers or deal with the lag of 1&1. I also use godaddy, they are faster (but I'm in the same state as their server). Little bit more a month though. Link to comment https://forums.phpfreaks.com/topic/136585-solved-mail-command-takes-a-long-time-to-finish/#findComment-713185 Share on other sites More sharing options...
trq Posted December 11, 2008 Share Posted December 11, 2008 not that I know of. PEAR is a library that must be on the server. I do not believe 1&1 has that library since their Linux server is mostly neglected by them. Anyone can use a PEAR module on any server. You just need to get hold of the right classes. Anyways, yes, I have heard people suggest that you may have more luck through phpmailer, I'm not sure about the PEAR one. Link to comment https://forums.phpfreaks.com/topic/136585-solved-mail-command-takes-a-long-time-to-finish/#findComment-713194 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.