TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 11-15-2007, 02:48 PM   #1 (permalink)
The Contributor
 
webosb's Avatar
 
Join Date: Nov 2007
Posts: 41
Thanks: 24
webosb is on a distinguished road
Default 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);
	}
webosb is offline  
Reply With Quote
Old 11-16-2007, 01:59 AM   #2 (permalink)
The Contributor
 
dschreck's Avatar
 
Join Date: Nov 2007
Location: California
Posts: 82
Thanks: 0
dschreck is on a distinguished road
Default

Firstly, I'd recommend PHP Mailer: http://phpmailer.sourceforge.net/

I've used that MIME Mail class, and I prefer PHPMailer over it, especially in reliance and speed. I've seen this mail class run on sites with hundreds of new sign ups a day, and never break under the load.

I'd also use the SMTP option with PHPMailer, as Apache + PHP wasn't really designed to send email, w/ the Mail function. Connecting directly the SMTP to send out email is much faster and takes a lot of the load off of PHP.

As far as the queue goes, you can do it several ways...
You could add it to a file, then a cron goes through and grabs like, the first 100 lines, sends out those emails every 5 mins or so.
Or, you can have it in a DB, and when you insert they sign up, insert them into your Database, then have the CRON run every like... 3 - 5 mins, or whatever delay you want, and it goes through the DB and finds all of the users that have signed up, but have yet to receive their E-mail.
dschreck is offline  
Reply With Quote
The Following User Says Thank You to dschreck For This Useful Post:
webosb (12-05-2007)
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 07:30 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design