public static function socket_send($socket, $data)
    {
        $serialized = serialize($data);
        $hdr = pack('N', strlen($serialized));    // 4 byte length
        $buffer = $hdr . $serialized;
        $total = strlen($buffer);
        while (true) {
            $sent = socket_write($socket, $buffer);
            if ($sent === false) {
                // @todo handle error?
                //$error = socket_strerror(socket_last_error());
                break;
            }
            if ($sent >= $total) {
                break;
            }
            $total -= $sent;
            $buffer = substr($buffer, $sent);
        }
    }
public static function socket_send($socket, $data)
    {
        $serialized = serialize($data);
        $hdr = pack('N', strlen($serialized));    // 4 byte length
        $buffer = $hdr . $serialized;
        $total = strlen($buffer);
        while (true) {
            $sent = socket_write($socket, $buffer);
            if ($sent === false) {
                // @todo handle error?
                //$error = socket_strerror(socket_last_error());
                break;
            }
            if ($sent >= $total) {
                break;
            }
            $total -= $sent;
            $buffer = substr($buffer, $sent);
        }
    }
public static function socket_send ( $ socket , $ data ) { $ serialized = serialize ( $ data ) ; $ hdr = pack ( 'N' , strlen ( $ serialized ) ) ; // 4 byte length $ buffer = $ hdr . $ serialized ; $ total = strlen ( $ buffer ) ; while ( true ) { $ sent = socket_write ( $ socket , $ buffer ) ; if ( $ sent === false ) { // @todo handle error? //$error = socket_strerror(socket_last_error()); break ; } if ( $ sent >= $ total ) { break ; } $ total -= $ sent ; $ buffer = substr ( $ buffer , $ sent ) ; } }
Write the data to the socket in a predetermined format
Write the data to the socket in a predetermined format