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.
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.
This means that when you use PHP_BINARY_READ then this system call will be used to read from the underlying socket. The remark about safety for binary data is explained by contrasting this with the alternative which reads
PHP_NORMAL_READ - reading stops at \n or \r.
Hence, if you would like to read one line at a time, then use PHP_NORMAL_READ. Otherwise, use PHP_BINARY_READ (which is default).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With