The value of the $ type parameter in socket_read ()

I am trying to create a tcp / ip socket connection from a C # application with a PHP 5.3 script using PHP sockets. A C # application needs to send JSON strings to a PHP script.

My question regarding the socket_read manual : What does this mean:

"PHP_BINARY_READ (Default) - use the system recv() function.
Safe for reading binary data."

      

What exactly does PHP_BINARY_READ do and why should I use recv () function when using this parameter?

Any help is appreciated.

+3


source to share


2 answers


The important part is what the documentation says about another choice:

  • PHP_NORMAL_READ - reading stops at \n

    or \r

    .


Select PHP_NORMAL_READ

if your socket is a text based text protocol. Select PHP_BINARY_READ

if your socket is something else.

+4


source


This means that when you use PHP_BINARY_READ, then this system call will be used to read from the underlying socket. The safety note for binary data is because it is compared to the alternative that reads

PHP_NORMAL_READ - reading stops at \ n or \ r.



Hence, if you want to read one line at a time, use PHP_NORMAL_READ. Otherwise use PHP_BINARY_READ (which is the default).

+3


source







All Articles