Search code examples
phpsocketsphp-5.3unix-socket

Meaning of the $type parameter in socket_read()


I try to create a tcp/ip socket connection from a c# app to a PHP 5.3 script using PHP sockets. The c# app should send JSON strings to the PHP script.

My question in regard to the socket_read manual: What do they mean with:

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

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

Any help is highly appreciated.


Solution

  • The important part is what the documentation says about the other choice:

    • PHP_NORMAL_READ - reading stops at \n or \r.

    Pick PHP_NORMAL_READ if your socket is a line-oriented text protocol. Pick PHP_BINARY_READ if your socket is anything else.