fputs example

/** * Send a request * * @param string $request your request without newline * @return null * @throws Zend_Mail_Protocol_Exception */
    public function sendRequest($request)
    {
        $result = @fputs($this->_socket, $request . "\r\n");
        if (!$result) {
            /** * @see Zend_Mail_Protocol_Exception */
            throw new Zend_Mail_Protocol_Exception('send failed - connection closed?');
        }
    }


    /** * read a response * * @param boolean $multiline response has multiple lines and should be read until "<nl>.<nl>" * @return string response * @throws Zend_Mail_Protocol_Exception */
public function sendRequest($command$tokens = array(), &$tag = null)
    {
        if (!$tag) {
            ++$this->_tagCount;
            $tag = 'TAG' . $this->_tagCount;
        }

        $line = $tag . ' ' . $command;

        foreach ($tokens as $token) {
            if (is_array($token)) {
                if (@fputs($this->_socket, $line . ' ' . $token[0] . "\r\n") === false) {
                    /** * @see Zend_Mail_Protocol_Exception */
                    throw new Zend_Mail_Protocol_Exception('cannot write - connection closed?');
                }
                if (!$this->_assumedNextLine('+ ')) {
                    /** * @see Zend_Mail_Protocol_Exception */
                    throw new Zend_Mail_Protocol_Exception('cannot send literal string');
                }
                
if ($p_len === null) {
                if ($this->_compress_type == 'gz') {
                    @gzputs($this->_file, $p_binary_data);
                } else {
                    if ($this->_compress_type == 'bz2') {
                        @bzwrite($this->_file, $p_binary_data);
                    } else {
                        if ($this->_compress_type == 'lzma2') {
                            @xzwrite($this->_file, $p_binary_data);
                        } else {
                            if ($this->_compress_type == 'none') {
                                @fputs($this->_file, $p_binary_data);
                            } else {
                                $this->_error(
                                    'Unknown or missing compression type ('
                                    . $this->_compress_type . ')'
                                );
                            }
                        }
                    }
                }
            } else {
                if ($this->_compress_type == 'gz') {
                    @
if ($flags === null) {
            $flags = array(Zend_Mail_Storage::FLAG_SEEN);
        }
        $info = $this->_getInfoString($flags);
        $temp_file = $this->_createTmpFile($folder->getGlobalName());

        // TODO: handle class instances for $message         if (is_resource($message) && get_resource_type($message) == 'stream') {
            stream_copy_to_stream($message$temp_file['handle']);
        } else {
            fputs($temp_file['handle']$message);
        }
        fclose($temp_file['handle']);

        // we're adding the size to the filename for maildir++         $size = filesize($temp_file['filename']);
        if ($size !== false) {
            $info = ',S=' . $size . $info;
        }
        $new_filename = $temp_file['dirname'] . DIRECTORY_SEPARATOR;
        $new_filename .= $recent ? 'new' : 'cur';
        $new_filename .= DIRECTORY_SEPARATOR . $temp_file['uniq'] . $info;

        
$_is_proxy = true;
                $fp = fsockopen($proxy_host,$proxy_port,$errno,$errstr,$timeout);
            } else {
                $fp = fsockopen($server_name,$port,$errno,$errstr,$timeout);
            }

            if(!$fp) {
                trigger_error("[plugin] unable to fetch: $errstr ($errno)",E_USER_NOTICE);
                return;
            } else {
                if($_is_proxy) {
                    fputs($fp, 'GET ' . $params['file'] . " HTTP/1.0\r\n");
                } else {
                    fputs($fp, "GET $uri HTTP/1.0\r\n");
                }
                if(!empty($host)) {
                    fputs($fp, "Host: $host\r\n");
                }
                if(!empty($accept)) {
                    fputs($fp, "Accept: $accept\r\n");
                }
                if(!empty($agent)) {
                    fputs($fp, "User-Agent: $agent\r\n");
                }
// ----- Packed data     $v_binary_data = pack("VvvvvvVVVvv", 0x04034b50,
                          $p_header['version_extracted']$p_header['flag'],
                          $p_header['compression']$v_mtime$v_mdate,
                          $p_header['crc']$p_header['compressed_size'],
                          $p_header['size'],
                          strlen($p_header['stored_filename']),
                          $p_header['extra_len']);

    // ----- Write the first 148 bytes of the header in the archive     fputs($this->zip_fd, $v_binary_data, 30);

    // ----- Write the variable fields     if (strlen($p_header['stored_filename']) != 0)
    {
      fputs($this->zip_fd, $p_header['stored_filename']strlen($p_header['stored_filename']));
    }
    if ($p_header['extra_len'] != 0)
    {
      fputs($this->zip_fd, $p_header['extra']$p_header['extra_len']);
    }

    


        if ($this->timeout) {
            $fp = @fsockopen($this->server, $this->port, $errno$errstr$this->timeout);
        } else {
            $fp = @fsockopen($this->server, $this->port, $errno$errstr);
        }
        if (!$fp) {
            $this->error = new IXR_Error(-32300, 'transport error - could not open socket');
            return false;
        }
        fputs($fp$request);
        $contents = '';
        $debugContents = '';
        $gotFirstLine = false;
        $gettingHeaders = true;
        while (!feof($fp)) {
            $line = fgets($fp, 4096);
            if (!$gotFirstLine) {
                // Check line for '200'                 if (strstr($line, '200') === false) {
                    $this->error = new IXR_Error(-32300, 'transport error - HTTP status code was not 200');
                    return false;
                }
if($this->LocalEcho) echo "GET < ".rtrim($this->_message, CRLF).CRLF;
        $this->_code=(int)$regs[1];
        return $result;
    }

    function _exec($cmd$fnction="_exec") {
        if(!$this->_ready) {
            $this->PushError($fnction,'Connect first');
            return FALSE;
        }
        if($this->LocalEcho) echo "PUT > ",$cmd,CRLF;
        $status=@fputs($this->_ftp_control_sock, $cmd.CRLF);
        if($status===false) {
            $this->PushError($fnction,'socket write failed');
            return FALSE;
        }
        $this->_lastaction=time();
        if(!$this->_readmsg($fnction)) return FALSE;
        return TRUE;
    }

    function _data_prepare($mode=FTP_ASCII) {
        if(!$this->_settype($mode)) return FALSE;
        
Home | Imprint | This part of the site doesn't use cookies.