I have a socket mailer function that is horiffically slow... (about 3-4 per minute) It doesn't close the connection every time, but I am unsure how to just keep the socket open...
Any pointers ?
function socketmail($fromName, $fromAddress, $toArray, $subject, $message,$end) {
ini_set("sendmail_from", $fromAddress);
$handle = fsockopen ("192.168.150.5",25, $errno, $errstr, 30) or die("Could not talk to the sendmail server!<br/>$errno<br/>$errstr");
$rcv = fgets($handle, 1024);
fputs($handle, "HELO {$_SERVER['SERVER_NAME']}\r\n");
$rcv = fgets($handle, 1024);
while (list($toKey, $toValue) = each($toArray)) {
fputs($handle, "MAIL FROM:$fromAddress\r\n");
$rcv = fgets($handle, 1024);
fputs($handle, "RCPT TO:$toValue\r\n");
$rcv = fgets($handle, 1024);
fputs($handle, "DATA\r\n");
$rcv = fgets($handle, 1024);
fputs($handle, "Subject: $subject\r\n");
fputs($handle, "From: $fromName <$fromAddress>\r\n");
fputs($handle, "To: $toKey <$toValue>\r\n");
fputs($handle, "X-Sender: <$fromAddress>\r\n");
fputs($handle, "Return-Path: <$fromAddress>\r\n");
fputs($handle, "Errors-To: <$fromAddress>\r\n");
fputs($handle, "X-Mailer: PHP - SocketMail\r\n");
fputs($handle, "X-Priority: 3\r\n");
fputs($handle, "Content-Type: multipart/alternative;\r\n");
fputs($handle, " boundary=\"----=_NextPart_000_000A_01C3EE3F.867B1730\"\r\n");
fputs($handle, "\r\n");
fputs($handle, "This is a multi-part message in MIME format.\r\n");
fputs($handle, "\r\n");
fputs($handle, "------=_NextPart_000_000A_01C3EE3F.867B1730\r\n");
fputs($handle, "Content-Type: text/plain;\r\n");
fputs($handle, " charset=\"ISO 8859-1\"\r\n");
fputs($handle, "Content-Transfer-Encoding: base64\r\n");
fputs($handle, "\r\n");
fputs($handle, chunk_split(base64_encode($message)) . "\r\n");
fputs($handle, "\r\n");
fputs($handle, "------=_NextPart_000_000A_01C3EE3F.867B1730\r\n");
fputs($handle, "Content-Type: text/html;\r\n");
fputs($handle, " charset=\"ISO 8859-1\"\r\n");
fputs($handle, "Content-Transfer-Encoding: base64\r\n");
fputs($handle, "\r\n");
fputs($handle, chunk_split(base64_encode($message)) . "\r\n");
fputs($handle, "\r\n");
fputs($handle, "------=_NextPart_000_000A_01C3EE3F.867B1730--\r\n");
fputs($handle, "\r\n");
fputs($handle, ".\r\n");
$rcv = fgets($handle, 1024);
if (trim($rcv)=='250 OK')
{
return true;
}
else
{
return false;
}
fputs($handle, "RSET\r\n");
$rcv = fgets($handle, 1024);
}
if ($end==true)
{
fputs ($handle, "QUIT\r\n");
$rcv = fgets ($handle, 1024);
//echo("$rcv<br>");
fclose($handle);
ini_restore("sendmail_from");
}
}
called by
$end=($z<$nummails)?false:true;
$sent = socketmail($name, $email, $to, "Numbers Confirmation Request from Travel Trade", $content,$end);
So it specifies to close the connection after the last mail - I would have assumed that reopening the socket everytime would also slow this down, but how could I open a persistent or permanent connection to speed things up - as well as pass that connection string to the function every time ?
<just a little lost on this...>
Would pfsockopen work - cos it doesn't seem to for some reason.....