1

What's the difference between socket_read and socket_recv? I'm trying to use PHP sockets but I get this warning using socket_read:

socket_read(): unable to read from socket [10057]

This is the line of coding for that:

$strData = socket_read($resSock, 65536, PHP_BINARY_READ); 

Now when I use socket_recv, I get this warning:

socket_recv(): unable to read from socket [0]

And this is the line:

socket_recv($resSock, $strData, 65536, 0);

Please help me out here!

3
  • Since both functions are getting the same error, why does the difference between them matter? Commented May 2, 2014 at 20:32
  • I asked whats the difference Barmar. Commented May 2, 2014 at 20:33
  • And I answered below. But how is the difference relevant to fixing the problem? Commented May 2, 2014 at 20:36

1 Answer 1

3

socket_recv allows you to supply extra flags. socket_read() is equivalent to calling socket_recv() with flags = 0. socket_read() also allows you to specify PHP_NORMAL_READ, which only reads up to the next newline (so it's then equivalent to fgets()).

They're also called slightly differently. socket_read() returns the data; socket_recv() takes a variable as a reference parameter and updates it, returning the number of bytes read.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks mate, is there anyway I can get rid of that warning?
My guess is that $resSock is not a valid socket. Post your code that opens the network connection.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.