faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

14 of 21 people (67%) answered Yes
Recently 4 of 10 people (40%) answered Yes

Entry

How to post binary data in write() with PHP socket?

Feb 22nd, 2008 03:18
dman, Jonathan Sharp, chiu jansen, http://www.ttnr.org


I'm not aware of a binary safe function for socket(); But you can use 
the fsockopen() to create a socket....
Here's an example of using fputs() to write binary data (example from 
bschuetz@affinity.net on php.net's comments)
fputs($fp,$binary,strlen($binary));
Also adam@nedstat.nl posted a comment on specifying the length of 
binary data..
"A note about including length: if you are writing binary data you 
should *always* specify the data's length. The reason is that the 
operating system has a special character to denote end of *strings*, 
but not for binary data. Binary data can be anything, so you can't very 
well reserve an end-of-data character..."
http://php.net/fputs