Page 2 of 2

Posted: Wed May 02, 2007 5:22 am
by garethjax
d11wtq wrote:Does this hang too?
I'm here again. ;)
I've tried this code and it's not working (waited one minute and still no signs of life).

Posted: Wed May 02, 2007 6:57 am
by Chris Corbyn
Ok thank you for trying it :) I have no clue why some *nix systems do this and every time I try to seek help nobody seems to know how to resolve it. I have never been able to recreate this problem myself... I'm almost starting to wonder if it's a bug with a certain version of PHP4 since it never happens on PHP5. The call to stat() must be hanging now, whereas before it was the attempt to call popen() on the file.

Code: Select all

if (stat("/usr/sbin/sendmail")) {
  echo "Stat ok";
}
else {
  echo "Stat not ok";
}
I'll bring one of my old help threads back from the dead.

Posted: Wed May 02, 2007 1:32 pm
by billgoodyear
Hi,

Just want to let you know that i tried the BatchSend class out and its working so far brilliantly. I was having trouble sending a campaign and was trying to work out how to overcome transmission timeouts on SMTP connections when i saw this posting. I've implemented the solution on PHP4, using Apache James as the email system. The job is running now, and im doing mysql database commands now with the spool engine and i can see the number of spooled messages increasing as the batch send is running. Im also seeing that the batch send job is not dying with errors but is chugging away sending messages. Previously using just the regular batchsend it was stopping every few minutes with a timeout.

Thanks for this posting. Sending mass email campaigns is a huge issue - and its very difficult to find effective software to use. In our case we have over 800 online stores each store needing to send differently branded messages to their customers, and your solution has been the most ideal that we have been able to find.

Thanks,

Bill Goodyear.

Posted: Thu May 03, 2007 5:20 am
by Chris Corbyn
That's good to hear ~billgoodyear :)

~garethjax, I just had a thought. Some users have reported (in much older code however) that manually closing the process can solve hangs. Does this work?

Code: Select all

<?php 

require_once 'lib/Swift/Connection/Sendmail.php'; 
require_once 'lib/Swift.php'; 

$sendmail =& new Swift_Connection_Sendmail(); 
$sendmail->start(); 
$sendmail->stop();

echo "I got here ok";
If that works, just make a call to $swift->disconnect() near the end of your script. I'm going to add a destructor for this in PHP4 with register_shutdown_function() now I come to think of it.

Posted: Fri May 04, 2007 4:15 am
by garethjax
d11wtq wrote:That's good to hear ~billgoodyear :)

~garethjax, I just had a thought. Some users have reported (in much older code however) that manually closing the process can solve hangs. Does this work?
Yes it works!

Posted: Fri May 04, 2007 5:01 am
by Chris Corbyn
garethjax wrote:
d11wtq wrote:That's good to hear ~billgoodyear :)

~garethjax, I just had a thought. Some users have reported (in much older code however) that manually closing the process can solve hangs. Does this work?
Yes it works!
Ok, I've already changed this to happen at script shutdown ready for the new release so this should no longer need to be explicitly done. Incidentally it must be a bug with some versions of PHP4 because the problem is something to do with PHP losing contact with the resource handles in the scope of an object by the time the script is shutting down... so I globalised the resources which fixed it in the 3 different PHP4 versions I test with, but clearly not all versions.

Posted: Sun May 06, 2007 7:48 am
by Chris Corbyn
The BatchMailer class is now a part of the standard package. $swift->batchSend() actually invokes it so unless you want to use some of the additional features available by using the class directly (sleep-on-errors, max-retries per-address, max successive failures, getFailedRecipients()) you can just go back to using $swift->batchSend like before.

Changes available in 3.2.0, just released.

EDIT | ~garethjax, the sendmail hang should now be solved too.

Posted: Tue May 29, 2007 2:10 pm
by billgoodyear
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Im having problems with the new batchmailer.

Specifically, when you used to be able to set the REPLY to and also pass the address as an address object.

Now, when using batchmail, i find that the sender is sent only as an email address, not as the name, and that the replyto is being ignored.

Is the process for passing an Address Object different for the new batch send. BTW, i found i had these two same objects when the first edition of the temporary batchmailer was first written as well.  

One other niggly problem, i occasionally run out of memory. Should i just bump up my memory limits or am i doing something wrong?

Here is my code (sanitized for userids etc).

Code: Select all

$message =& new Swift_Message($parms["subject"], $parms["message"], "text/html");
				$message->setReturnPath("XXXXXX");
				$message->headers->set("Reply-To", $parms["replyto"]);
				$address = new Swift_Address("XXXXXX", $parms["storename"]);  # $parms["replyto"]

				if (! is_array($parms["email_address"])) {
					$parms["email_address"] = array($parms["email_address"]);
				}

				$max = count($parms["email_address"]);
				$count = 0;
				$batchcount = 0;
				foreach ($parms["email_address"] as $email_address) {
					$count++;
					$batchcount++;

					if ($count == 0 || $count == 1) {
						$recipients =& new Swift_RecipientList();
					}

					$recipients->addTo($email_address);

					if ($count >= $max or $batchcount > 50) {
						$smtp =& new Swift_Connection_SMTP("database", 26);

						$smtp->setTimeout(90); 
						$smtp->attachAuthenticator(new Swift_Authenticator_PLAIN());
						$smtp->setUsername("XXXXX");
						$smtp->setPassword("YYYYY"); 

						$swift =& new Swift($smtp);

		 				$swift->batchSend($message, $recipients, $address);
#						echo "\nBatch Transmitted\n" . var_dump($recipients) . "\n";
						unset($recipients);
						$swift->disconnect();

						$count = 0;
					}
				}

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue May 29, 2007 2:23 pm
by billgoodyear
Thanks for the tip - will do. Also when i stated two objects, i meant these same two issues. Looks like my fingers were not on the same page as my brain when typing.
Looking forward to any light that can be shed!