public function write($data)
    {
        if (!$this->connected && !$this->connect()) {
            return false;
        }
        $totalBytes = strlen($data);
        $written = 0;
        while ($written < $totalBytes) {
            $rv = fwrite($this->connection, substr($data, $written));
            if ($rv === false || $rv === 0) {
                return $written;
            }
            $written += $rv;
        }

        return $written;
    }
public function write($data)
    {
        if (!$this->connected && !$this->connect()) {
            return false;
        }
        $totalBytes = strlen($data);
        $written = 0;
        while ($written < $totalBytes) {
            $rv = fwrite($this->connection, substr($data, $written));
            if ($rv === false || $rv === 0) {
                return $written;
            }
            $written += $rv;
        }

        return $written;
    }
public function write ( $ data ) { if ( ! $ this -> connected && ! $ this -> connect ( ) ) { return false ; } $ totalBytes = strlen ( $ data ) ; $ written = 0 ; while ( $ written < $ totalBytes ) { $ rv = fwrite ( $ this -> connection , substr ( $ data , $ written ) ) ; if ( $ rv === false || $ rv === 0 ) { return $ written ; } $ written += $ rv ; } return $ written ; }
Write data to the socket.

The bool false return value is deprecated and will be int 0 in the next major.
Please code respectively to be future proof.

@param string $data The data to write to the socket.
@return int|false Bytes written.
Write data to the socket .