Net/Socket.php
public function write($data, $blocksize = null)
    {
        if (!is_resource($this->fp)) {
            return $this->raiseError('not connected');
        }

        if (null === $blocksize && !OS_WINDOWS) {
            $written = @fwrite($this->fp, $data);

            // Check for timeout or lost connection
            if ($written === false) {
                $meta_data = $this->getStatus();

                if (!is_array($meta_data)) {
                    return $meta_data; // PEAR_Error
                }

                if (!empty($meta_data['timed_out'])) {
                    return $this->raiseError('timed out');
                }
            }

            return $written;
        } else {
            if (null === $blocksize) {
                $blocksize = 1024;
            }

            $pos = 0;
            $size = strlen($data);
            while ($pos < $size) {
                $written = @fwrite($this->fp, substr($data, $pos, $blocksize));

                // Check for timeout or lost connection
                if ($written === false) {
                    $meta_data = $this->getStatus();

                    if (!is_array($meta_data)) {
                        return $meta_data; // PEAR_Error
                    }

                    if (!empty($meta_data['timed_out'])) {
                        return $this->raiseError('timed out');
                    }

                    return $written;
                }

                $pos += $written;
            }

            return $pos;
        }
    }
public function write($data, $blocksize = null)
    {
        if (!is_resource($this->fp)) {
            return $this->raiseError('not connected');
        }

        if (null === $blocksize && !OS_WINDOWS) {
            $written = @fwrite($this->fp, $data);

            // Check for timeout or lost connection
            if ($written === false) {
                $meta_data = $this->getStatus();

                if (!is_array($meta_data)) {
                    return $meta_data; // PEAR_Error
                }

                if (!empty($meta_data['timed_out'])) {
                    return $this->raiseError('timed out');
                }
            }

            return $written;
        } else {
            if (null === $blocksize) {
                $blocksize = 1024;
            }

            $pos = 0;
            $size = strlen($data);
            while ($pos < $size) {
                $written = @fwrite($this->fp, substr($data, $pos, $blocksize));

                // Check for timeout or lost connection
                if ($written === false) {
                    $meta_data = $this->getStatus();

                    if (!is_array($meta_data)) {
                        return $meta_data; // PEAR_Error
                    }

                    if (!empty($meta_data['timed_out'])) {
                        return $this->raiseError('timed out');
                    }

                    return $written;
                }

                $pos += $written;
            }

            return $pos;
        }
    }
public function write ( $ data , $ blocksize = null ) { if ( ! is_resource ( $ this -> fp ) ) { return $ this -> raiseError ( 'not connected' ) ; } if ( null === $ blocksize && ! OS_WINDOWS ) { $ written = @ fwrite ( $ this -> fp , $ data ) ; // Check for timeout or lost connection if ( $ written === false ) { $ meta_data = $ this -> getStatus ( ) ; if ( ! is_array ( $ meta_data ) ) { return $ meta_data ; // PEAR_Error } if ( ! empty ( $ meta_data [ 'timed_out' ] ) ) { return $ this -> raiseError ( 'timed out' ) ; } } return $ written ; } else { if ( null === $ blocksize ) { $ blocksize = 1024 ; } $ pos = 0 ; $ size = strlen ( $ data ) ; while ( $ pos < $ size ) { $ written = @ fwrite ( $ this -> fp , substr ( $ data , $ pos , $ blocksize ) ) ; // Check for timeout or lost connection if ( $ written === false ) { $ meta_data = $ this -> getStatus ( ) ; if ( ! is_array ( $ meta_data ) ) { return $ meta_data ; // PEAR_Error } if ( ! empty ( $ meta_data [ 'timed_out' ] ) ) { return $ this -> raiseError ( 'timed out' ) ; } return $ written ; } $ pos += $ written ; } return $ pos ; } }
Write a specified amount of data.

@param string $data Data to write.
@param integer $blocksize Amount of data to write at once.
NULL means all at once.

@access public
@return mixed If the socket is not connected, returns an instance of
PEAR_Error.
If the write succeeds, returns the number of bytes written.
If the write fails, returns false.
If the socket times out, returns an instance of PEAR_Error.
Write a specified amount of data .