src/Network/Connection.php
private function writeData($stompFrame, $timeout)
    {
        $data = (string) $stompFrame;
        $offset = 0;
        $size = strlen($data);
        $lastByteTime = microtime(true);
        do {
            $written = @fwrite($this->connection, substr($data, $offset), $this->maxWriteBytes);

            if ($written === false) {
                throw new ConnectionException('Was not possible to write frame!', $this->activeHost);
            }

            if ($written > 0) {
                // offset tracking
                $offset += $written;
                $lastByteTime = microtime(true);
            } else {
                // timeout tracking
                if ((microtime(true) - $lastByteTime) > $timeout) {
                    throw new ConnectionException(
                        'Was not possible to write frame! Write operation timed out.',
                        $this->activeHost
                    );
                }
            }
            // keep some time to breath
            if ($written < $size) {
                time_nanosleep(0, 2500000); // 2.5ms / 0.0025s
            }
        } while ($offset < $size);
    }
private function writeData($stompFrame, $timeout)
    {
        $data = (string) $stompFrame;
        $offset = 0;
        $size = strlen($data);
        $lastByteTime = microtime(true);
        do {
            $written = @fwrite($this->connection, substr($data, $offset), $this->maxWriteBytes);

            if ($written === false) {
                throw new ConnectionException('Was not possible to write frame!', $this->activeHost);
            }

            if ($written > 0) {
                // offset tracking
                $offset += $written;
                $lastByteTime = microtime(true);
            } else {
                // timeout tracking
                if ((microtime(true) - $lastByteTime) > $timeout) {
                    throw new ConnectionException(
                        'Was not possible to write frame! Write operation timed out.',
                        $this->activeHost
                    );
                }
            }
            // keep some time to breath
            if ($written < $size) {
                time_nanosleep(0, 2500000); // 2.5ms / 0.0025s
            }
        } while ($offset < $size);
    }
private function writeData ( $ stompFrame , $ timeout ) { $ data = ( string ) $ stompFrame ; $ offset = 0 ; $ size = strlen ( $ data ) ; $ lastByteTime = microtime ( true ) ; do { $ written = @ fwrite ( $ this -> connection , substr ( $ data , $ offset ) , $ this -> maxWriteBytes ) ; if ( $ written === false ) { throw new ConnectionException ( 'Was not possible to write frame!' , $ this -> activeHost ) ; } if ( $ written > 0 ) { // offset tracking $ offset += $ written ; $ lastByteTime = microtime ( true ) ; } else { // timeout tracking if ( ( microtime ( true ) - $ lastByteTime ) > $ timeout ) { throw new ConnectionException ( 'Was not possible to write frame! Write operation timed out.' , $ this -> activeHost ) ; } } // keep some time to breath if ( $ written < $ size ) { time_nanosleep ( 0 , 2500000 ) ; // 2.5ms / 0.0025s } } while ( $ offset < $ size ) ; }
Write passed data to the stream, respecting passed timeout.

@param Frame|string $stompFrame
@param float $timeout in seconds, supporting fractions
@throws ConnectionException
Write passed data to the stream respecting passed timeout .