HTTP
- Введение
- Установка и настройка
- Требования
- Установка HTTP-расширения — Установка/Конфигурирование
- Настройка во время выполнения
- Типы ресурсов
- Предопределенные константы
- Request Options — Options usable with the HttpRequest class and request functions
- HttpDeflateStream — The HttpDeflateStream class
- HttpDeflateStream::__construct — HttpDeflateStream class constructor
- HttpDeflateStream::factory — HttpDeflateStream class factory
- HttpDeflateStream::finish — Finalize deflate stream
- HttpDeflateStream::flush — Flush deflate stream
- HttpDeflateStream::update — Update deflate stream
- HttpInflateStream — The HttpInflateStream class
- HttpInflateStream::__construct — HttpInflateStream class constructor
- HttpInflateStream::factory — HttpInflateStream class factory
- HttpInflateStream::finish — Finalize inflate stream
- HttpInflateStream::flush — Flush inflate stream
- HttpInflateStream::update — Update inflate stream
- HttpMessage — The HttpMessage class
- HttpMessage::addHeaders — Add headers
- HttpMessage::__construct — HttpMessage constructor
- HttpMessage::detach — Detach HttpMessage
- HttpMessage::factory — Create HttpMessage from string
- HttpMessage::fromEnv — Create HttpMessage from environment
- HttpMessage::fromString — Create HttpMessage from string
- HttpMessage::getBody — Get message body
- HttpMessage::getHeader — Get header
- HttpMessage::getHeaders — Get message headers
- HttpMessage::getHttpVersion — Get HTTP version
- HttpMessage::getParentMessage — Get parent message
- HttpMessage::getRequestMethod — Get request method
- HttpMessage::getRequestUrl — Get request URL
- HttpMessage::getResponseCode — Get response code
- HttpMessage::getResponseStatus — Get response status
- HttpMessage::getType — Get message type
- HttpMessage::guessContentType — Guess content type
- HttpMessage::prepend — Prepend message(s)
- HttpMessage::reverse — Reverse message chain
- HttpMessage::send — Send message
- HttpMessage::setBody — Set message body
- HttpMessage::setHeaders — Set headers
- HttpMessage::setHttpVersion — Set HTTP version
- HttpMessage::setRequestMethod — Set request method
- HttpMessage::setRequestUrl — Set request URL
- HttpMessage::setResponseCode — Set response code
- HttpMessage::setResponseStatus — Set response status
- HttpMessage::setType — Set message type
- HttpMessage::toMessageTypeObject — Create HTTP object regarding message type
- HttpMessage::toString — Get string representation
- HttpQueryString — The HttpQueryString class
- HttpQueryString::__construct — HttpQueryString constructor
- HttpQueryString::get — Get (part of) query string
- HttpQueryString::mod — Modifiy query string copy
- HttpQueryString::set — Set query string params
- HttpQueryString::singleton — HttpQueryString singleton
- HttpQueryString::toArray — Get query string as array
- HttpQueryString::toString — Get query string
- HttpQueryString::xlate — Change query strings charset
- HttpRequest — The HttpRequest
- HttpRequest::addCookies — Add cookies
- HttpRequest::addHeaders — Add headers
- HttpRequest::addPostFields — Add post fields
- HttpRequest::addPostFile — Add post file
- HttpRequest::addPutData — Add put data
- HttpRequest::addQueryData — Add query data
- HttpRequest::addRawPostData — Add raw post data
- HttpRequest::addSslOptions — Add ssl options
- HttpRequest::clearHistory — Clear history
- HttpRequest::__construct — HttpRequest constructor
- HttpRequest::enableCookies — Enable cookies
- HttpRequest::getContentType — Get content type
- HttpRequest::getCookies — Get cookies
- HttpRequest::getHeaders — Get headers
- HttpRequest::getHistory — Get history
- HttpRequest::getMethod — Get method
- HttpRequest::getOptions — Get options
- HttpRequest::getPostFields — Get post fields
- HttpRequest::getPostFiles — Get post files
- HttpRequest::getPutData — Get put data
- HttpRequest::getPutFile — Get put file
- HttpRequest::getQueryData — Get query data
- HttpRequest::getRawPostData — Get raw post data
- HttpRequest::getRawRequestMessage — Get raw request message
- HttpRequest::getRawResponseMessage — Get raw response message
- HttpRequest::getRequestMessage — Get request message
- HttpRequest::getResponseBody — Get response body
- HttpRequest::getResponseCode — Get response code
- HttpRequest::getResponseCookies — Get response cookie(s)
- HttpRequest::getResponseData — Get response data
- HttpRequest::getResponseHeader — Get response header(s)
- HttpRequest::getResponseInfo — Get response info
- HttpRequest::getResponseMessage — Get response message
- HttpRequest::getResponseStatus — Get response status
- HttpRequest::getSslOptions — Get ssl options
- HttpRequest::getUrl — Get url
- HttpRequest::resetCookies — Reset cookies
- HttpRequest::send — Send request
- HttpRequest::setBody — Set request body to send, overwriting previously set request body.
- HttpRequest::setContentType — Set content type
- HttpRequest::setCookies — Set cookies
- HttpRequest::setHeaders — Set headers
- HttpRequest::setMethod — Set method
- HttpRequest::setOptions — Set options
- HttpRequest::setPostFields — Set post fields
- HttpRequest::setPostFiles — Set post files
- HttpRequest::setPutData — Set put data
- HttpRequest::setPutFile — Set put file
- HttpRequest::setQueryData — Set query data
- HttpRequest::setRawPostData — Set raw post data
- HttpRequest::setSslOptions — Set ssl options
- HttpRequest::setUrl — Set URL
- HttpRequestPool — The HttpRequestPool class
- HttpRequestPool::attach — Attach HttpRequest
- HttpRequestPool::__construct — HttpRequestPool constructor
- HttpRequestPool::__destruct — HttpRequestPool destructor
- HttpRequestPool::detach — Detach HttpRequest
- HttpRequestPool::getAttachedRequests — Get attached requests
- HttpRequestPool::getFinishedRequests — Get finished requests
- HttpRequestPool::reset — Reset request pool
- HttpRequestPool::send — Send all requests
- HttpRequestPool::socketPerform — Perform socket actions
- HttpRequestPool::socketSelect — Perform socket select
- HttpResponse — The HttpResponse
- HttpResponse::capture — Capture script output
- HttpResponse::getBufferSize — Get buffer size
- HttpResponse::getCache — Get cache
- HttpResponse::getCacheControl — Get cache control
- HttpResponse::getContentDisposition — Get content disposition
- HttpResponse::getContentType — Get content type
- HttpResponse::getData — Get data
- HttpResponse::getETag — Get ETag
- HttpResponse::getFile — Get file
- HttpResponse::getGzip — Get gzip
- HttpResponse::getHeader — Get header
- HttpResponse::getLastModified — Get last modified
- HttpResponse::getRequestBody — Get request body
- HttpResponse::getRequestBodyStream — Получить поток тела запроса
- HttpResponse::getRequestHeaders — Get request headers
- HttpResponse::getStream — Get Stream
- HttpResponse::getThrottleDelay — Get throttle delay
- HttpResponse::guessContentType — Guess content type
- HttpResponse::redirect — Redirect
- HttpResponse::send — Send response
- HttpResponse::setBufferSize — Set buffer size
- HttpResponse::setCache — Set cache
- HttpResponse::setCacheControl — Set cache control
- HttpResponse::setContentDisposition — Set content disposition
- HttpResponse::setContentType — Set content type
- HttpResponse::setData — Set data
- HttpResponse::setETag — Set ETag
- HttpResponse::setFile — Set file
- HttpResponse::setGzip — Set gzip
- HttpResponse::setHeader — Set header
- HttpResponse::setLastModified — Set last modified
- HttpResponse::setStream — Set stream
- HttpResponse::setThrottleDelay — Set throttle delay
- HttpResponse::status — Send HTTP response status
- HTTP Функции
- http_cache_etag — Caching by ETag
- http_cache_last_modified — Caching by last modification
- http_chunked_decode — Decode chunked-encoded data
- http_deflate — Deflate data
- http_inflate — Inflate data
- http_build_cookie — Build cookie string
- http_date — Compose HTTP RFC compliant date
- http_get_request_body_stream — Get request body as stream
- http_get_request_body — Get request body as string
- http_get_request_headers — Get request headers as array
- http_match_etag — Match ETag
- http_match_modified — Match last modification
- http_match_request_header — Match any header
- http_support — Check built-in HTTP support
- http_negotiate_charset — Negotiate client's preferred character set
- http_negotiate_content_type — Negotiate client's preferred content type
- http_negotiate_language — Negotiate client's preferred language
- ob_deflatehandler — Deflate output handler
- ob_etaghandler — ETag output handler
- ob_inflatehandler — Inflate output handler
- http_parse_cookie — Parse HTTP cookie
- http_parse_headers — Parse HTTP headers
- http_parse_message — Parse HTTP messages
- http_parse_params — Parse parameter list
- http_persistent_handles_clean — Clean up persistent handles
- http_persistent_handles_count — Stat persistent handles
- http_persistent_handles_ident — Get/set ident of persistent handles
- http_get — Perform GET request
- http_head — Perform HEAD request
- http_post_data — Perform POST request with pre-encoded data
- http_post_fields — Perform POST request with data to be encoded
- http_put_data — Perform PUT request with data
- http_put_file — Perform PUT request with file
- http_put_stream — Perform PUT request with stream
- http_request_body_encode — Encode request body
- http_request_method_exists — Check whether request method exists
- http_request_method_name — Get request method name
- http_request_method_register — Register request method
- http_request_method_unregister — Unregister request method
- http_request — Perform custom request
- http_redirect — Issue HTTP redirect
- http_send_content_disposition — Send Content-Disposition
- http_send_content_type — Send Content-Type
- http_send_data — Send arbitrary data
- http_send_file — Send file
- http_send_last_modified — Send Last-Modified
- http_send_status — Send HTTP response status
- http_send_stream — Send stream
- http_throttle — HTTP throttling
- http_build_str — Build query string
- http_build_url — Build a URL
- Constant hash database
- Клиентская библиотека работы с URL
- Event
- File Alteration Monitor
- FTP
- Gearman
- Net Gopher
- Gupnp
- Hyperwave API
- Облегчённый протокол доступа к каталогам (LDAP)
- Memcache
- Memcached
- mqseries
- Network
- RRDtool
- Simple Asynchronous Messaging
- SNMP
- Сокеты
- Secure Shell2
- Stomp Client
- Support Vector Machine
- Subversion
- TCP Wrappers
- Varnish
- YAZ
- YP/NIS
- ZMQ
Коментарии
Documentation for version 2 of this extension is available here:
http://devel-m6w6.rhcloud.com/mdref/http/
For all those who still have code using the old pecl_http1 API and want to use PHP 5.6, you may want to make a wrapper on top of pecl_http2.
The following code will work with PHP 5.6 if you use a wrapper:
<?php
$r = new HttpRequest($post_url, HttpRequest::METH_POST);
$r->setHeaders(array('User-Agent' => $user_agent));
$r->addPostFields($post_data);
try {
$r->send();
if ($r->getResponseCode() == 200) {
echo $r->getResponseBody();
}
} catch (HttpException $ex) {
// catch exception
}
?>
Here is the code of the wrapper of HttpRequst on top of pecl_http2 with PHP 5.6:
<?php
class HttpRequest {
private $url;
private $method;
private $headers;
private $post_fields;
private $http2_request;
private $http2_client;
private $http2_response;
const METH_POST = 'POST';
const METH_GET = 'GET';
function __construct($url, $method) {
$this->url = $url;
$this->method = $method;
$this->headers = array();
$this->post_fields = null;
}
function setHeaders($headers) {
$this->headers = $headers;
}
function addPostFields($post_fields) {
$this->post_fields = $post_fields;
}
function send() {
$this->http2_request = new httpClientRequest($this->method, $this->url, $this->headers);
if ($this->method == HttpRequest::METH_POST && $this->post_fields) {
$this->http2_request->getBody()->append(new httpQueryString($this->post_fields));
}
$this->http2_client = new httpClient;
$this->http2_client->enqueue($this->http2_request)->send();
}
function getResponseCode() {
if (!$this->http2_response) $this->http2_response = $this->http2_client->getResponse($this->http2_request);
return $this->http2_response->getResponseCode();
}
function getResponseBody() {
if (!$this->http2_response) $this->http2_response = $this->http2_client->getResponse($this->http2_request);
return $this->http2_response->getBody();
}
}
?>
Feel free to extend and share your thoughts in order to get even more functionality of HttpRequest work with PHP 5.6
There is a sniff for PHP_CodeSniffer to checks for HTTP extension compatibility between 1.x and 2.x versions, useful for version migrations, scanning your code looking for forbidden functions and classes.
https://github.com/jkribeiro/PHPHttpCompatibility