Back to index

php5  5.3.10
Public Member Functions | Public Attributes
HTTPRequest Class Reference

List of all members.

Public Member Functions

 HTTPRequest ($URL, $headers=array(), $options=array(), $postdata=NULL)
 doRequest ()
 _validateUrl ()
 _parseResponse ()
_getRequest ()
_sendHTTP ()

Public Attributes

 $headers = array()
 $timeout = 4
 $urlparts = NULL
 $url = ''
 $userAgent = 'PHP-Test-Harness'
 $options = array()
 $postdata = NULL
 $errmsg = ''
 $errno = 0
 $response
 $response_headers
 $outgoing_payload
 $incoming_payload = ''

Detailed Description

Definition at line 234 of file server-tests.php.


Member Function Documentation

Definition at line 326 of file server-tests.php.

    {
        $fullpath = $this->urlparts['path'].
                    (isset($this->urlparts['query'])?'?'.$this->urlparts['query']:'').
                    (isset($this->urlparts['fragment'])?'#'.$this->urlparts['fragment']:'');
        if (isset($this->options['proxy_host'])) {
            $fullpath = 'http://'.$this->urlparts['host'].':'.$this->urlparts['port'].$fullpath;
        }
        if (isset($this->options['proxy_user'])) {
            $headers['Proxy-Authorization'] = 'Basic ' . base64_encode($this->options['proxy_user'].":".$this->options['proxy_pass']);
        }
        $headers['User-Agent'] = $this->userAgent;
        $headers['Host'] = $this->urlparts['host'];
        $headers['Content-Length'] = strlen($this->postdata);
        $headers['Content-Type'] = 'application/x-www-form-urlencoded';
        if (isset($this->headers)) {
            $headers = array_merge($headers, $this->headers);
        }
        $headertext = '';
        foreach ($headers as $k => $v) {
            $headertext .= "$k: $v\r\n";
        }
        $method = trim($this->options['method'])?strtoupper(trim($this->options['method'])):'GET';
        $this->outgoing_payload = 

Definition at line 302 of file server-tests.php.

    {
        if (preg_match("/^(.*?)\r?\n\r?\n(.*)/s", $this->incoming_payload, $match)) {
            $this->response = $match[2];
            if (preg_match("/^HTTP\/1\.. (\d+).*/s",$match[1],$status) && !$status[1]) {
                    $this->errmsg = "HTTP Response $status[1] Not Found";
                    return FALSE;
            }
            $rh = preg_split("/[\n\r]+/",$match[1]);
            $this->response_headers = array();
            foreach ($rh as $line) {
                if (strpos($line, ':')!==false) {
                    $line = explode(":", $line, 2);
                    $this->response_headers[trim($line[0])] = trim($line[1]);
                }
            }
            $this->response_headers['Status']=$status[1];
            // if no content, return false

Definition at line 356 of file server-tests.php.

    {
        $this->_getRequest();
        $host = $this->urlparts['host'];
        $port = $this->urlparts['port'];
        if (isset($this->options['proxy_host'])) {
            $host = $this->options['proxy_host'];
            $port = isset($this->options['proxy_port'])?$this->options['proxy_port']:8080;
        }
        // send
        if ($this->timeout > 0) {
            $fp = fsockopen($host, $port, $this->errno, $this->errmsg, $this->timeout);
        } else {
            $fp = fsockopen($host, $port, $this->errno, $this->errmsg);
        }
        if (!$fp) {
            $this->errmsg = "Connect Error to $host:$port";
            return NULL;
        }
        if ($this->timeout > 0) {
            // some builds of php do not support this, silence
            // the warning
            @socket_set_timeout($fp, $this->timeout);
        }
        if (!fputs($fp, $this->outgoing_payload, strlen($this->outgoing_payload))) {
            $this->errmsg = "Error Sending Request Data to $host";
            return NULL;
        }
        
        while ($data = fread($fp, 32768)) {
            $this->incoming_payload .= $data;
        }

Definition at line 286 of file server-tests.php.

    {
        if ( ! is_array($this->urlparts) ) {
            return FALSE;
        }
        if (!isset($this->urlparts['host'])) {
            $this->urlparts['host']='127.0.0.1';
        }
        if (!isset($this->urlparts['port'])) {
            $this->urlparts['port'] = 80;

Definition at line 276 of file server-tests.php.

    {
        if (!$this->_validateUrl()) return;
        
HTTPRequest::HTTPRequest ( URL,
headers = array(),
options = array(),
postdata = NULL 
)

Definition at line 266 of file server-tests.php.

    {
        $this->urlparts = @parse_url($URL);
        $this->url = $URL;

Here is the call graph for this function:


Member Data Documentation

Definition at line 243 of file server-tests.php.

Definition at line 244 of file server-tests.php.

Definition at line 236 of file server-tests.php.

Definition at line 248 of file server-tests.php.

Definition at line 241 of file server-tests.php.

Definition at line 247 of file server-tests.php.

Definition at line 242 of file server-tests.php.

Definition at line 245 of file server-tests.php.

Definition at line 246 of file server-tests.php.

Definition at line 237 of file server-tests.php.

Definition at line 239 of file server-tests.php.

Definition at line 238 of file server-tests.php.

Definition at line 240 of file server-tests.php.


The documentation for this class was generated from the following file: