Page 1 of 1
catchable transport connection failure
Posted: Sun Apr 19, 2009 1:23 pm
by AlexC
G'morning,
In the 3 series of Swift Mailer, I recall there being a way to catch transport connection failures very easily. However, with 4(.0.3) a typo in the hostname when connecting (using SMTP transport here), for example, will result in PHP warnings, such as:
Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: Name or service not known
Is there a 'nice' way to handle these errors (such as catching an exception like before), so I don't in fact get them at all? This is for an application that will have its configuration adjusted by users (admins) and if they make a typo, having PHP warnings fill their logs/browser isn't too good.
Regards,
Re: catchable transport connection failure
Posted: Sun Apr 19, 2009 11:17 pm
by Chris Corbyn
PHP's own error handling features can deal with these.
Look into set_error_handler()
I could use error suppression throughout my code, but it slows things down considerably.
Re: catchable transport connection failure
Posted: Mon Apr 20, 2009 1:12 am
by AlexC
Indeed, though I'd rather not have to deal with them in that way - it wouldn't work too good for this. So there is no way of handling connection failures like in the old 3 series?

Re: catchable transport connection failure
Posted: Mon Apr 20, 2009 1:31 am
by Chris Corbyn
AlexC wrote:Indeed, though I'd rather not have to deal with them in that way - it wouldn't work too good for this. So there is no way of handling connection failures like in the old 3 series?

Placing an @ sign in front of the call to send() would suppress this error. In version 3, I assume you're referring to the PHP4 version of it? This was slightly different since the errors were ones generated by Swift Mailer... the PHP generated ones exhibited this same behaviour.
Re: catchable transport connection failure
Posted: Mon Apr 20, 2009 2:21 am
by AlexC
Hi Chris,
No this was in the PHP5 version, upon connection if it failed it would throw a 'Swift_ConnectionException' exception, of which I could catch and handle how I wished. I'm aware of PHPs error suppression, though it seems like a step-backwards from the 3 series in handling it. Could this be rectified in later versions, to provide a cleaner way of handling connection errors?
Re: catchable transport connection failure
Posted: Mon Apr 20, 2009 5:49 am
by Chris Corbyn
I;m not sure what you mean. Swift Mailer v4 still throws Exceptions on connection failures. It throws Swift_TransportException. If it's not throwing that, fsockopen() must be generating an error but returning a resource incorrectly, which is a bug in PHP itself. I've only ever seen this happen to one other person.
Are you saying that a Swift_TransportException is not thrown?
Re: catchable transport connection failure
Posted: Mon Apr 20, 2009 5:58 am
by AlexC
From what I could see, yeah it was not throwing the exception. I don't have access to the code fully at the moment, so I shall have to check when I get home. That does sound like what is happening, though. This is on PHP 5.2.9.
Btw, unrelated to this - looking at your avatar, do you have your PPL, or is someone else flying?
Re: catchable transport connection failure
Posted: Mon Apr 20, 2009 8:07 am
by Chris Corbyn
AlexC wrote:Btw, unrelated to this - looking at your avatar, do you have your PPL, or is someone else flying?
My friend was flying

PPL would be nice but I don't have one. It was a nice flight over the coast out here... over
the twelve apostles.
Re: catchable transport connection failure
Posted: Mon Apr 20, 2009 10:40 am
by AlexC
Ah, appears the exception is being thrown - not sure what was going on this morning with it then. Ghosts I tell you.
That's cool, looks like a nice place to go flying indeed! I recently got my PPL, though no where as nice to fly like that in sunny UK
