0

I use the PHP function fread to read the data from a stream opened with

$fh=fopen('http://.....');

i set the timeout for the stream with

socket_set_timeout($fh,10);

if a timeout happened during the fread execution then can i somehow to know about this?

$contents = fread($fh, 1024);

if timeout happens then will $contents be equal empty string or FALSE ? how to know that timeout happened? is there a way?

Roman Gelembjuk
  • 1,797
  • 2
  • 25
  • 50

2 Answers2

1

According to the doc page for that function:

When the stream times out, the 'timed_out' key of the array returned by stream_get_meta_data() is set to TRUE, although no error/warning is generated.

So there are no errors/warnings generated, but inspecting the output from stream_get_meta_data will give you a clue.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
oliakaoil
  • 1,615
  • 2
  • 15
  • 36
0

fread() will return '' (empty string) when a timeout occurs unlike socket_read() which returns false.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
pavlovich
  • 1,935
  • 15
  • 20