11-15-2007, 02:48 PM
|
#1 (permalink)
|
|
The Contributor
Join Date: Nov 2007
Posts: 41
Thanks: 24
|
Creating Mail Queues
Does anyone have any experience creating mail queues? I have a script that emails people everytime they sign up with a MIME email class ( http://www.phpclasses.org/browse/package/9.html) but it can cause high server load when there is a bit of traffic... So I figure I can reduce some server load if I were able to create some kind of mail queue.... So if someone can point me into the right direction, that'll be great.
Thanks in advance.
The problem from the email class is this function (which takes a 1143ms to execute under some stress - the profiler shows strcmp and strlen being the longest to execute):
Code:
Function QuotedPrintableEncode($text,$header_charset='',$break_lines=1)
{
$ln=strlen($text);
$h=(strlen($header_charset)>0);
if($h)
{
$s=array(
'='=>1,
'?'=>1,
'_'=>1,
'('=>1,
')'=>1,
'<'=>1,
'>'=>1,
'@'=>1,
','=>1,
';'=>1,
'"'=>1,
'\\'=>1,
/*
'/'=>1,
'['=>1,
']'=>1,
':'=>1,
'.'=>1,
*/
);
$b=$space=$break_lines=0;
for($i=0;$i<$ln;$i++)
{
if(IsSet($s[$text[$i]]))
{
$b=1;
break;
}
switch($o=Ord($text[$i]))
{
case 9:
case 32:
$space=$i+1;
$b=1;
break 2;
case 10:
case 13:
break 2;
default:
if($o<32
|| $o>127)
{
$b=1;
break 2;
}
}
}
if($i==$ln)
return($text);
if($space>0)
return(substr($text,0,$space).($space<$ln ? $this->QuotedPrintableEncode(substr($text,$space),$header_charset,0) : ""));
}
for($w=$e='',$n=0, $l=0,$i=0;$i<$ln;$i++)
{
$c=$text[$i];
$o=Ord($c);
$en=0;
switch($o)
{
case 9:
case 32:
if(!$h)
{
$w=$c;
$c='';
}
else
{
if($b)
{
if($o==32)
$c='_';
else
$en=1;
}
}
break;
case 10:
case 13:
if(strlen($w))
{
if($break_lines
&& $l+3>75)
{
$e.='='.$this->line_break;
$l=0;
}
$e.=sprintf('=%02X',Ord($w));
$l+=3;
$w='';
}
$e.=$c;
if($h)
$e.="\t";
$l=0;
continue 2;
case 46:
case 70:
case 102:
$en=(!$h && ($l==0 || $l+1>75));
break;
default:
if($o>127
|| $o<32
|| !strcmp($c,'='))
$en=1;
elseif($h
&& IsSet($s[$c]))
$en=1;
break;
}
if(strlen($w))
{
if($break_lines
&& $l+1>75)
{
$e.='='.$this->line_break;
$l=0;
}
$e.=$w;
$l++;
$w='';
}
if(strlen($c))
{
if($en)
{
$c=sprintf('=%02X',$o);
$el=3;
$n=1;
$b=1;
}
else
$el=1;
if($break_lines
&& $l+$el>75)
{
$e.='='.$this->line_break;
$l=0;
}
$e.=$c;
$l+=$el;
}
}
if(strlen($w))
{
if($break_lines
&& $l+3>75)
$e.='='.$this->line_break;
$e.=sprintf('=%02X',Ord($w));
}
if($h
&& $n)
return('=?'.$header_charset.'?q?'.$e.'?=');
else
return($e);
}
|
|
|
|