0

I am reading binary data from a network socket in PHP. With files, you can use the 'b' mode to specify that the file is binary and should be read as such, but how does one mark a network socket as being binary?

Nate
  • 12,499
  • 5
  • 45
  • 60
Gavin Brown
  • 113
  • 1
  • 1
  • 5

2 Answers2

1

Network sockets are always assumed to be binary data, so the flag's not necessary. The "binary" name for the flag on file-based operations is somewhat badly chosen. It should be the "do not translate line-ending characters" flag.

Otherwise the obvious reading would be that if you don't specify b, the file should be read in analog mode.

Marc B
  • 356,200
  • 43
  • 426
  • 500
  • Thanks. Turns out that my issue was due to some unexpected buffering on the socket, not because the data I was getting was encoded in a funny way. – Gavin Brown Jun 30 '11 at 07:18
0

Using unpack() is how php read binary data.

//example:
$un = unpack("V",$some_bin_string);
Naftali
  • 144,921
  • 39
  • 244
  • 303