Search code examples
phpsocketserror-handlingfgets

How to obtain error for functions stream_get_line and fgets?


I have a code where I open a socket connection. From time to time it happens that fgets returns false. I would like to find out why it happens. Is there a function that would provide more details about last error on $handle? Something like preg_last_error, json_last_error, …

The same question can be applied to function stream_get_line().

I use PHP 5.4 and E_ALL is in error_reporting (i.e. it includes even E_NOTICE). No error was thrown.


Solution

  • More information about stream can be retrieved by using stream_get_meta_data(). However, I solved the issue by rewriting my code to use socket_* functions. The API provides socket_last_error function which helps a lot.