EventHttpConnection::makeRequest

(PECL event >= 1.4.0-beta)
Makes 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.

Parameters:
req

The connection object over which to send the request.

type

One of EventHttpRequest::CMD_* constants .

uri

The URI associated with the request.

Returns:

Returns TRUE on success. Otherwise FALSE.

Examples:
EventHttpConnection::makeRequest() example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?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 $s, PHP_EOL;
            }
        }
    }
 
    $base->exit(NULL);
}
 
$address "127.0.0.1";
$port = 80;
 
$base new EventBase();
$conn new EventHttpConnection($base, NULL, $address$port);
$conn->setTimeout(5);
$req new EventHttpRequest("_request_handler"$base);
 
$req->addHeader("Host"$address, EventHttpRequest::OUTPUT_HEADER);
$req->addHeader("Content-Length""0", EventHttpRequest::OUTPUT_HEADER);
$conn->makeRequest($req, EventHttpRequest::CMD_GET, "/index.cphp");
 
$base->loop();
?>

The above example will output something similar to:

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

EventHttpRequest::addHeader() -

doc_php
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.