4
I usually use the class SplFileObject
to be able to work with files. The same does not happen with sockets, when necessary to connect, it is necessary to use the function fsockopen
or stream_socket_client
.
I need that, in a particular code snippet, in case the fwrite
cannot write the data, throw an exception.
Is there any way to do that?
Which error of? a fatal error?
– rray
@rray, specifically cannot write the data. That is, some kind of connection error, or delay. I don’t know how to say exactly, but I think of an error when writing data to a socket connection
– Wallace Maxters
Have you tried using the
set_error_handler
, when an error occurs you capture it and launches an Exception.– rray
I wanted to capture the specific error of a
fwrite
– Wallace Maxters
That would be http://php.net/manual/en/function.fwrite.php#81269 ?
– rray
fwrite() === FALSE
? I wonder if we could make onefwrite($data, 'teste') or $this->callException()
? I’m sure you won’t accept a throw after theOR
– Wallace Maxters
Specific error type, with details of the occurred ?
– Edilson
No need to be specific. The
fwrite
just need not be able to write on the current connection.– Wallace Maxters
He still has doubts about the subject?
– durtto