[SOLVED] howto catch a swift exception in php4

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

garethjax
Forum Newbie
Posts: 18
Joined: Mon Apr 23, 2007 7:16 am

Post 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).
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
billgoodyear
Forum Newbie
Posts: 16
Joined: Fri Apr 20, 2007 11:00 am

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
garethjax
Forum Newbie
Posts: 18
Joined: Mon Apr 23, 2007 7:16 am

Post 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!
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
billgoodyear
Forum Newbie
Posts: 16
Joined: Fri Apr 20, 2007 11:00 am

Post 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]
billgoodyear
Forum Newbie
Posts: 16
Joined: Fri Apr 20, 2007 11:00 am

Post 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!
Post Reply