google-measurement-php-client icon indicating copy to clipboard operation
google-measurement-php-client copied to clipboard

When Internet is not available socket_connect throws a 'Host name lookup failure' PHP error

Open daN4cat opened this issue 7 years ago • 2 comments

In no Internet available condition, the socket_connect call in Socket.php createConnection function throws the following error:

A PHP Error was encountered Servetity: Warning

Message: socket_connect(): Host loockup failed [-10002]: Host name lookup failure Filename: Adapter/Socket.php

Line Number: 32

Backtrace: [...]

that ignoring the possible false return, and any exception throwing and try&catch.

Is there any way to avoid that error message in that specific call?

daN4cat avatar Nov 11 '16 08:11 daN4cat

Thanks @daN4cat! I personally think it is better to throw an exception and let the consumer decide how to handle this exception. But it would be better to throw an generic connection exception than the socket specific error. What is you opinion on this?

ins0 avatar Nov 12 '16 20:11 ins0

Ideally this should be captured at the level of function call and then throw the already existing exception, I believe we are saying the same.

The current way bypasses what is already in place and doesn't allow any sensible handling (e.g. switch off the GA feature, retry later, simple error logging) at top function caller level.

daN4cat avatar Nov 13 '16 10:11 daN4cat