EventHttpConnection::makeRequest

(PECL event >= 1.4.0-beta)

EventHttpConnection::makeRequestMakes an HTTP request over the specified connection

설명

public bool EventHttpConnection::makeRequest ( EventHttpRequest $req , int $type , string $uri )

Makes an HTTP request over the specified connection. type is one of EventHttpRequest::CMD_* constants.

인수

req

The connection object over which to send the request.

type

One of EventHttpRequest::CMD_* constants .

uri

The URI associated with the request.

반환값

Returns TRUE on success. Otherwise FALSE.

예제

Example #1 EventHttpConnection::makeRequest() example

<?php
function _request_handler($req$base) {
    echo 
__FUNCTION__PHP_EOL;

    if (
is_null($req)) {
        echo 
"Timed out\n";
    } else {
        
$response_code $req->getResponseCode();

        if (
$response_code == 0) {
            echo 
"Connection refused\n";
        } elseif (
$response_code != 200) {
            echo 
"Unexpected response: $response_code\n";
        } else {
            echo 
"Success: $response_code\n";
            
$buf $req->getInputBuffer();
            echo 
"Body:\n";
            while (
$s $buf->readLine(EventBuffer::EOL_ANY)) {
                echo 
$sPHP_EOL;
            }
        }
    }

    
$base->exit(NULL);
}

$address "127.0.0.1";
$port 80;

$base = new EventBase();
$conn = new EventHttpConnection($baseNULL$address$port);
$conn->setTimeout(5);
$req = new EventHttpRequest("_request_handler"$base);

$req->addHeader("Host"$addressEventHttpRequest::OUTPUT_HEADER);
$req->addHeader("Content-Length""0"EventHttpRequest::OUTPUT_HEADER);
$conn->makeRequest($reqEventHttpRequest::CMD_GET"/index.cphp");

$base->loop();
?>

위 예제의 출력 예시:

_request_handler
Success: 200
Body:
PHP, date:
2013-03-13T20:27:52+05:00

참고

add a note add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top