X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=docs%2Ffunctions.html;h=64d9c930cdb7b119e8a54a66231d4236340f8473;hb=5aa958980652d72433ba8e9e500b8dfd123d56a1;hp=1503d1a33ada8f096e9caa237a4bf1888c9d2d24;hpb=19ad90d1f12058345ceb651b4bed6ff0f298dd08;p=m6w6%2Fext-http diff --git a/docs/functions.html b/docs/functions.html index 1503d1a..64d9c93 100644 --- a/docs/functions.html +++ b/docs/functions.html @@ -72,20 +72,8 @@ looking like: "Wed, 22 Dec 2004 11:34:47 GMT"
Takes an optional unix timestamp as parameter.
Returns the HTTP date as string.
Build a complete URI according to the supplied parameters.
-If the url is already abolute but a different proto was supplied,
-only the proto part of the URI will be updated. If url has no
-path specified, the path of the current REQUEST_URI will be taken.
-The host will be taken either from the Host HTTP header of the client
-the SERVER_NAME or just localhost if prior are not available.
-If a port is pecified in either the url or as sperate parameter,
-it will be added if it differs from te default port for HTTP(S).
Returns the absolute URI as string.
-Examples:
+-
-<?php
$uri = http_build_uri("page.php", "https", NULL, 488);
?>
-
Returns the new URL as string on success or FALSE on failure.
This function negotiates the clients preferred language based on its
Accept-Language HTTP header. The qualifier is recognized and languages
@@ -113,6 +101,19 @@ if none match.
This function negotiates the clients preferred content type based on its
+Accept HTTP header. The qualifier is recognized and content types
+without qualifier are rated highest.
Expects an array as parameter cotaining the supported content types as values.
+If the optional second parameter is supplied, it will be filled with an
+array containing the negotiation results.
Returns the negotiated content type or the default content type
+(i.e. first array entry) if none match.
Example:
+
+<?php
$ctypes = array('application/xhtml+xml', 'text/html');
http_send_content_type(http_negotiate_content_type($ctypes));
?>
+
Send HTTP status code.
Expects an HTTP status code as parameter.
@@ -179,11 +180,10 @@ a "304 Not Modified" status code is issued.For use with ob_start(). Output buffer handler generating an ETag with
the hash algorythm specified with the INI setting "http.etag_mode".
Sets the throttle delay and send buffer size for use with http_send() API.
Provides a basic throttling mechanism, which will yield the current process
resp. thread until the entity has been completely sent, though.
Note: This doesn't really work with the FastCGI SAPI.
Expects a double parameter specifying the seconds too sleep() after
each chunk sent. Additionally accepts an optional int parameter
representing the chunk size in bytes.
Redirect to the given url.
-The supplied url will be expanded with http_build_uri(), the params array will
+The supplied url will be expanded with http_build_url(), the params array will
be treated with http_build_query() and the session identification will be appended
if session is true.
The HTTP response code will be set according to status.
@@ -205,7 +205,7 @@ You can use one of the following constants for convenience:
- HTTP_REDIRECT_TEMP 307 Temporary Redirect
Please see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3
for which redirect response code to use in which situation.
To be RFC compliant, "Redirecting to URI." will be displayed,
+
To be RFC compliant, "Redirecting to URL." will be displayed,
if the client doesn't redirect immediatly, and the request method was
another one than HEAD.
Returns FALSE on failure, or *exits* on success.
@@ -240,7 +240,15 @@ several consecutive HTTP messages.Expects a string parameter containing HTTP headers.
Returns an array on success, or FALSE on failure.
Example:
++
-<?php
$headers = "content-type: text/html; charset=UTF-8\r\n".
"Server: Funky/1.0\r\n".
"Set-Cookie: foo=bar\r\n".
"Set-Cookie: baz=quux\r\n".
"Folded: works\r\n\ttoo\r\n";
print_r(http_parse_headers($headers));
Array
(
[Content-Type] => text/html; chatset=UTF-8
[Server] => Funky/1.0
[Set-Cookie] => Array
(
[0] => foo=bar
[1] => baz=quux
)
[Folded] => works
too
?>
+<?php
$headers = "content-type: text/html; charset=UTF-8\r\n".
"Server: Funky/1.0\r\n".
"Set-Cookie: foo=bar\r\n".
"Set-Cookie: baz=quux\r\n".
"Folded: works\r\n\ttoo\r\n";
print_r(http_parse_headers($headers));
Array
(
[Content-Type] => text/html; chatset=UTF-8
[Server] => Funky/1.0
[Set-Cookie] => Array
(
[0] => foo=bar
[1] => baz=quux
)
[Folded] => works
too
)
?>
+
Parses HTTP cookies like sent in a response into a struct.
+Expects a string as parameter containing the value of a Set-Cookie response header.
+Returns an stdClass object with the cookie params as properties on success or FALSE on failure.
+Example:
+<?php
print_r(http_parse_cookie("foo=bar; path=/"));
stdClass Object
(
[name] => foo
[value] => bar
[path] => /
)
?>
- redirect: - compress: bool, whether to allow gzip/deflate content encoding
(defaults to true)
- port: int, use another port as specified in the url
- - referer: string, the referer to sends
+ - referer: string, the referer to send
- useragent: string, the user agent to send
(defaults to PECL::HTTP/version (PHP/version)))
- headers: array, list of custom headers as associative array
@@ -337,6 +345,70 @@ See http_get() for a full list of available options.Returns the request method name as string on success, or FALSE on failure.
string http_build_query(mixed formdata [, string prefix[, string arg_separator]])
Generates a form-encoded query string from an associative array or object.
+string http_deflate(string data[, int flags = 0])
+Compress data with gzip, zlib AKA deflate or raw deflate encoding.
+Expects the first parameter to be a string containing the data that should
+
+be encoded.Returns the encoded string on success, or NULL on failure.
+string http_inflate(string data)
+Uncompress data compressed with either gzip, deflate AKA zlib or raw
+
+deflate encoding.Expects a string as parameter containing the compressed data.
+Returns the decoded string on success, or NULL on failure.
+string ob_deflatehandler(string data, int mode)
+For use with ob_start(). The deflate output buffer handler can only be used once.
+
+It conflicts with ob_gzhanlder and zlib.output_compression as well and should
+not be used after ext/mbstrings mb_output_handler and ext/sessions URL-Rewriter (AKA
+session.use_trans_sid).string ob_inflatehandler(string data, int mode)
+For use with ob_start(). Same restrictions as with ob_deflatehandler apply.
+int http_support([int feature = 0])
+Check for feature that require external libraries.
+Accpepts an optional in parameter specifying which feature to probe for.
+
+If the parameter is 0 or omitted, the return value contains a bitmask of
+all supported features that depend on external libraries.Available features to probe for are:
+
Returns int, whether requested feature is supported, or a bitmask with
+all supported features.
Creates a new HttpDeflateStream object instance.
+Accepts an optional int parameter specifying how to initialize the deflate stream.
+Passes more data through the deflate stream.
+Expects a string parameter containing (a part of) the data to deflate.
+Returns deflated data on success or FALSE on failure.
+Flushes the deflate stream.
+Returns some deflated data as string on success or FALSE on failure.
+Finalizes the deflate stream. The deflate stream can be reused after finalizing.
+Returns the final part of deflated data.
+Passes more data through the inflate stream.
+Expects a string parameter containing (a part of) the data to inflate.
+Returns inflated data on success or FALSE on failure.
+Flush the inflate stream.
+Returns some inflated data as string on success or FALSE on failure.
+Finalizes the inflate stream. The inflate stream can be reused after finalizing.
+Returns the final part of inflated data.
Expects a string parameter containing the request method name.
Returns TRUE on success, or FALSE if the message is not of type
HttpMessage::TYPE_REQUEST or an invalid request method was supplied.
Get the Request URI of the Message.
-Returns the request uri as string on success, or FALSE if the message
+
Get the Request URL of the Message.
+Returns the request url as string on success, or FALSE if the message
is not of type HttpMessage::TYPE_REQUEST.
Set the Request URI of the HTTP Message.
-Expects a string parameters containing the request uri.
+Set the Request URL of the HTTP Message.
+Expects a string parameters containing the request url.
Returns TRUE on success, or FALSE if the message is not of type
-HttpMessage::TYPE_REQUEST or supplied URI was empty.
Get the HTTP Protocol Version of the Message.
Returns the HTTP protocol version as string.
@@ -426,17 +498,25 @@ This provides limited functionality compared to HttpRequest and HttpResponse.Accepts a bool parameter which specifies whether the returned stringReturns the full message as string.
+Implements Countable.
+Returns the number of parent messages + 1.
+Implements Serializable.
+Returns the serialized representation of the HttpMessage.
+Implements Serializable.
+Re-constructs the HttpMessage based upon the serialized string.
Instantiate a new HttpRequest object.
Accepts a string as optional parameter containing the target request url.
Additianally accepts an optional int parameter specifying the request method
-to use.
Throws HttpException.
-Destroys the HttpRequest object.
Set the request options to use. See http_get() for a full list of available options.
Accepts an array as optional parameters, wich values will overwrite the
@@ -494,7 +574,7 @@ pairs to add.
Set the request method.
Expects an int as parameter specifying the request method to use.
-In PHP 5.1+ HttpRequest::METH, otherwise the HTTP_METH constants can be used.
Returns TRUE on success, or FALSE on failure.
Get the previously set request method.
@@ -642,6 +722,17 @@ cycle. references the last received response. Use HttpMessage::getParentMessage()Note that the internal request message is immutable, that means that the
+request message received through HttpRequest::getRequestMessage() will
+always look the same for the same request, regardless of any changes you
+may have made to the returned object.
Throws HttpMalformedHeadersException, HttpEncodingException.
+Get sent HTTP message.
+Returns an HttpMessage in a form of a string
+Get the entire HTTP response.
+Returns the complete web server response, including the headers in a form of a string.
Get all sent requests and received responses as an HttpMessage object.
If you don't want to record history at all, set the instance variable
@@ -650,20 +741,26 @@ HttpRequest::$recoedHistory to FALSE.
The object references the last received response, use HttpMessage::getParentMessage()
to access the data of previously sent requests and received responses.
Throws HttpMalformedHeaderException.
+Note that the internal history is immutable, that means that any changes
+you make the the message list won't affect a history message list newly
+created by another call to HttpRequest::getHistory().
Throws HttpMalformedHeaderException, HttpEncodingException.
Clear the history.
Send the HTTP request.
Returns the received response as HttpMessage object.
+NOTE: While an exception may be thrown, the transfer could have succeeded
+at least partially, so you might want to check the return values of various
+HttpRequest::getResponse*() methods.
Throws HttpRuntimeException, HttpRequestException,
HttpMalformedHeaderException, HttpEncodingException.
GET example:
-<?php
$r = new HttpRequest('http://example.com/feed.rss', HTTP_GET);
$r->setOptions(array('lastmodified' => filemtime('local.rss')));
$r->addQueryData(array('category' => 3));
try {
$r->send();
if ($r->getResponseCode() == 200) {
file_put_contents('local.rss', $r->getResponseBody());
}
} catch (HttpException $ex) {
echo $ex;
}
?>
+<?php
$r = new HttpRequest('http://example.com/feed.rss', HttpRequest::METH_GET);
$r->setOptions(array('lastmodified' => filemtime('local.rss')));
$r->addQueryData(array('category' => 3));
try {
$r->send();
if ($r->getResponseCode() == 200) {
file_put_contents('local.rss', $r->getResponseBody());
}
} catch (HttpException $ex) {
echo $ex;
}
?>
POST example:
-<?php
$r = new HttpRequest('http://example.com/form.php', HTTP_POST);
$r->setOptions(array('cookies' => array('lang' => 'de')));
$r->addPostFields(array('user' => 'mike', 'pass' => 's3c|r3t'));
$r->addPostFile('image', 'profile.jpg', 'image/jpeg');
try {
echo $r->send()->getBody();
} catch (HttpException $ex) {
echo $ex;
}
?>
+<?php
$r = new HttpRequest('http://example.com/form.php', HttpRequest::METH_POST);
$r->setOptions(array('cookies' => array('lang' => 'de')));
$r->addPostFields(array('user' => 'mike', 'pass' => 's3c|r3t'));
$r->addPostFile('image', 'profile.jpg', 'image/jpeg');
try {
echo $r->send()->getBody();
} catch (HttpException $ex) {
echo $ex;
}
?>
Instantiate a new HttpRequestPool object. An HttpRequestPool is
able to send several HttpRequests in parallel.
WARNING: Don't attach/detach HttpRequest objects to the HttpRequestPool
-object while you're using the implemented Interator interface.
Accepts virtual infinite optional parameters each referencing an
HttpRequest object.
Throws HttpRequestException, HttpRequestPoolException, HttpInvalidParamException.
+Throws HttpRequestPoolException (HttpRequestException, HttpInvalidParamException).
Example:
@@ -702,12 +799,11 @@ HttpRequestPool object.
<?php
try {
$pool = new HttpRequestPool(
new HttpRequest('http://www.google.com/', HttpRequest::METH_HEAD),
new HttpRequest('http://www.php.net/', HttpRequest::METH_HEAD)
);
$pool->send();
foreach($pool as $request) {
printf("%s is %s (%d)\n",
$request->getUrl(),
$request->getResponseCode() ? 'alive' : 'not alive',
$request->getResponseCode()
);
}
} catch (HttpException $e) {
echo $e;
}
?>
bool HttpRequestPool::send()
Send all attached HttpRequest objects in parallel.
Returns TRUE on success, or FALSE on failure.
-Throws HttpSocketException, HttpRequestException,
+
-HttpRequestPoolException, HttpMalformedHeaderException.Throws HttpRequestPoolException (HttpSocketException, HttpRequestException, HttpMalformedHeaderException).
protected bool HttpRequestPool::socketPerform()
Returns TRUE until each request has finished its transaction.
Usage:
-<?php
while ($pool->socketPerform()) {
do_something_else();
if (!$pool->socketSelect()) {
die('Socket error');
}
}
?>
+<?php
class MyPool extends HttpRequestPool
{
public function send()
{
while ($this->socketPerform()) {
if (!$this->socketSelect()) {
throw new HttpSocketExcpetion;
}
}
}
protected final function socketPerform()
{
$result = parent::socketPerform();
foreach ($this->getFinishedRequests() as $r) {
$this->detach($r);
// handle response of finished request
}
return $result;
}
}
?>
protected bool HttpRequestPool::socketSelect()
@@ -723,6 +819,16 @@ HttpRequestPoolException, HttpMalformedHeaderException.Implements Iterator::next().
void HttpRequestPool::rewind()
Implements Iterator::rewind().
+int HttpRequestPool::count()
+Implements Countable.
+Returns the number of attached HttpRequest objects.
+array HttpRequestPool::getAttachedRequests()
+Get attached HttpRequest objects.
+Returns an array containing all currently attached HttpRequest objects.
+array HttpRequestPool::getFinishedRequests()
+Get attached HttpRequest objects that already have finished their work.
+Returns an array containing all attached HttpRequest objects that
+already have finished their work.
http_response_object.c
static bool HttpResponse::setHeader(string name, mixed value[, bool replace = true])
@@ -885,12 +991,14 @@ http.cache_log is set.
Generated at: Wed, 05 Oct 2005 15:34:24 +0000
+Generated at: Tue, 03 Jan 2006 20:04:51 +0100