Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP socket_recv and socket_read

Tags:

php

From reading the PHP manual, socket_recv and socket_read function looks same to me, both function get data from client.

can any one tell me what are different between those 2 functions?

like image 859
anru Avatar asked May 30 '12 09:05

anru


2 Answers

socket_recv returns the number of bytes received socket_read returns the data that has been received

With socket_recv you can read bytes from the buffer AND know how many bytes have been recevied. With socket_read you can only read a specific amount of data from the buffer

like image 165
bart s Avatar answered Oct 11 '22 00:10

bart s


From http://www.faqs.org/faqs/unix-faq/socket/#b:

2.18. What is the difference between read() and recv()?

From Andrew Gierth ([email protected]):

read() is equivalent to recv() with a flags parameter of 0. Other
values for the flags parameter change the behaviour of recv().
Similarly, write() is equivalent to send() with flags == 0.

like image 39
Esailija Avatar answered Oct 11 '22 01:10

Esailija