EventHttpConnection::makeRequest
(PECL event >= 1.4.0-beta)
EventHttpConnection::makeRequest — Makes an HTTP request over the specified connection
Description
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.
Return Values
Returns TRUE
on success. Otherwise FALSE
.
Examples
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 $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() - Adds an HTTP header to the headers of the request
- Функция EventHttpConnection::__construct() - Constructs EventHttpConnection object
- Функция EventHttpConnection::getBase() - Returns event base associated with the connection
- Функция EventHttpConnection::getPeer() - Gets the remote address and port associated with the connection
- Функция EventHttpConnection::makeRequest() - Makes an HTTP request over the specified connection
- Функция EventHttpConnection::setCloseCallback() - Set callback for connection close
- Функция EventHttpConnection::setLocalAddress() - Sets the IP address from which HTTP connections are made
- Функция EventHttpConnection::setLocalPort() - Sets the local port from which connections are made
- Функция EventHttpConnection::setMaxBodySize() - Sets maximum body size for the connection
- Функция EventHttpConnection::setMaxHeadersSize() - Sets maximum header size
- Функция EventHttpConnection::setRetries() - Sets the retry limit for the connection
- Функция EventHttpConnection::setTimeout() - Sets the timeout for the connection
Коментарии
404 Not Found