| ユーザフォーラムで議論/質問 | マニュアル検索 | ハイライト | ハイライトオフ | ポータル | php spot |
AdaptersAdapters – Classes that actually perform the request
OverviewAdapters in HTTP_Request2 package are classes responsible for establishing the actual connection to the remote server, writing requests and reading responses. Adapter can be set either via a configuration parameter (see: Configuration) or by HTTP_Request2::setAdapter() method. The package currently contains three adapters:
Other adapters may be created by subclassing an abstract HTTP_Request2_Adapter class and implementing its HTTP_Request2_Adapter::sendRequest() method. Socket Adapter Issues
Note, that the above two problems mean that no peer validation whatsoever is possible when doing a https:// request through proxy using Socket adapter. If this is an issue for you, consider using Curl Adapter instead. Curl Adapter IssuesWhen doing a POST request with file uploads or reading the request body from file, HTTP_Request2 streams files from disk to reduce memory consumption and to allow monitoring the request progress. This is done by setting up a CURLOPT_READFUNCTION callback. PHP does not allow setting another callback, CURLOPT_IOCTLFUNCTION (see PHP bug #47204) so the request body can not be "rewound" when another request should be performed. Thus a request with a non-empty body to a resource protected by Digest authentication or to a page that does a redirect when follow_redirects is enabled will fail. Since release 0.5.0 HTTP_Request2 works around this problem by reading the whole request body into memory. Of course this may be an issue when the request body is huge, so consider using Socket Adapter. Setting strict_redirects configuration parameter to TRUE will only have effect on Curl Adapter if CURLOPT_POSTREDIR (see PHP bug #49571) is available in cURL extension. It is not yet available in PHP 5.3.1. Using Mock adapterHTTP_Request2_Adapter_Mock::addResponse() method can accept either a HTTP response (instance of HTTP_Request2_Response, a string, a pointer to an open file) or an Exception. The latter may be useful to test that your application degrades gracefully when the remote server is not available due to some network problems. Several responses may be added via addResponse() to simulate a HTTP transaction consisting of multiple requests and responses. They will be returned by the Adapter in the order they were added.
Returning responses and throwing exceptions
<?php
The above code will output:
Mock Adapter also has two static helper methods HTTP_Request2_Adapter_Mock::createResponseFromString() and HTTP_Request2_Adapter_Mock::createResponseFromFile() which build HTTP_Request2_Response objects from either a string containing the complete HTTP response or a pointer to an open file with such response, respectively. |
各種マニュアル:
PHPマニュアル |
PEARマニュアル |
Smarty(英語)マニュアル |
PHP-GTKマニュアル |
「Adapters」をGoogle検索
|