user3334215
user3334215

Reputation: 37

PHP Socket Read/Socket Receive

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!

Upvotes: 1

Views: 1263

Answers (1)

Barmar
Barmar

Reputation: 782315

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.

Upvotes: 3

Related Questions