EventHttpRequest::__construct
(PECL event >= 1.4.0-beta)
EventHttpRequest::__construct — Constructs EventHttpRequest object
Описание
Constructs EventHttpRequest object.
Список параметров
-
callback
-
Gets invoked on requesting path. Should match the following prototype:
-
data
-
User custom data passed to the callback.
Возвращаемые значения
Returns EventHttpRequest object.
Примеры
Пример #1 EventHttpRequest::__construct() 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();
?>
Смотрите также
- EventHttpRequest::cancel() - Cancels a pending HTTP request
- EventHttpRequest::addHeader() - Adds an HTTP header to the headers of the request
- Функция EventHttpRequest::addHeader() - Adds an HTTP header to the headers of the request
- Функция EventHttpRequest::cancel() - Cancels a pending HTTP request
- Функция EventHttpRequest::clearHeaders() - Removes all output headers from the header list of the request
- Функция EventHttpRequest::closeConnection() - Closes associated HTTP connection
- Функция EventHttpRequest::__construct() - Constructs EventHttpRequest object
- Функция EventHttpRequest::findHeader() - Finds the value belonging a header
- Функция EventHttpRequest::free() - Frees the object and removes associated events
- Функция EventHttpRequest::getBufferEvent() - Returns EventBufferEvent object
- Функция EventHttpRequest::getCommand() - Returns the request command(method)
- Функция EventHttpRequest::getConnection() - Returns EventHttpConnection object
- Функция EventHttpRequest::getHost() - Returns the request host
- Функция EventHttpRequest::getInputBuffer() - Returns the input buffer
- Функция EventHttpRequest::getInputHeaders() - Returns associative array of the input headers
- Функция EventHttpRequest::getOutputBuffer() - Returns the output buffer of the request
- Функция EventHttpRequest::getOutputHeaders() - Returns associative array of the input headers
- Функция EventHttpRequest::getResponseCode() - Returns the the response code
- Функция EventHttpRequest::getUri() - Returns the request URI
- Функция EventHttpRequest::removeHeader() - Removes an HTTP header from the headers of the request
- Функция EventHttpRequest::sendError() - Send an HTML error message to the client
- Функция EventHttpRequest::sendReply() - Send an HTML reply to the client
- Функция EventHttpRequest::sendReplyChunk() - Send another data chunk as part of an ongoing chunked reply
- Функция EventHttpRequest::sendReplyEnd() - Complete a chunked reply, freeing the request as appropriate
- Функция EventHttpRequest::sendReplyStart() - Initiate a chunked reply
Коментарии
404 Not Found