X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=docs%2Ffunctions.html;h=e44c943d97bd552c9f16ec0599f07c49994ff4de;hb=cdbe702a66e68d97885d5305278246c2630c9f10;hp=4c6ff04d2811160a889484a4d473818310061dd9;hpb=7f914f24a4276b5c3489d410814f8d1125c8264f;p=m6w6%2Fext-http
diff --git a/docs/functions.html b/docs/functions.html
index 4c6ff04..e44c943 100644
--- a/docs/functions.html
+++ b/docs/functions.html
@@ -71,9 +71,9 @@ The qualifier is recognized and languages without qualifier are rated highest.
the supported languages as array values.
-Example:
-<?php
$langs = array(
'en-US',// default
'fr',
'fr-FR',
'de',
'de-DE',
'de-AT',
'de-CH',
);
include './langs/'. http_negotiate_language($langs) .'.php';
?>
-
+Example:@@ -87,9 +87,9 @@ The qualifier is recognized and charset without qualifier are rated highest.
+<?php
$langs = array(
'en-US',// default
'fr',
'fr-FR',
'de',
'de-DE',
'de-AT',
'de-CH',
);
include './langs/'. http_negotiate_language($langs) .'.php';
?>
+
the supported charsets as array values.
-Example:
-<?php
$charsets = array(
'iso-8859-1', // default
'iso-8859-2',
'iso-8859-15',
'utf-8'
);
$pref = http_negotiate_charset($charsets);
if (!strcmp($pref, 'iso-8859-1')) {
iconv_set_encoding('internal_encoding', 'iso-8859-1');
iconv_set_encoding('output_encoding', $pref);
ob_start('ob_iconv_handler');
}
?>
-
+Example:@@ -131,9 +131,9 @@ a "304 Not Modified" status code is issued.
+<?php
$charsets = array(
'iso-8859-1', // default
'iso-8859-2',
'iso-8859-15',
'utf-8'
);
$pref = http_negotiate_charset($charsets);
if (!strcmp($pref, 'iso-8859-1')) {
iconv_set_encoding('internal_encoding', 'iso-8859-1');
iconv_set_encoding('output_encoding', $pref);
ob_start('ob_iconv_handler');
}
?>
+
void http_throttle(double sec[, long bytes = 2097152])
Use with http_send() API.
-Example:
-<?php
// ~ 20 kbyte/s
# http_throttle(1, 20000);
# http_throttle(0.5, 10000);
# http_throttle(0.1, 2000);
http_send_file('document.pdf');
?>
-
+Example:@@ -160,16 +160,20 @@ if the client doesn't redirect immediatly. Returns false on failure.
+<?php
// ~ 20 kbyte/s
# http_throttle(1, 20000);
# http_throttle(0.5, 10000);
# http_throttle(0.1, 2000);
http_send_file('document.pdf');
?>
+
array http_split_response(string http_response)
This function splits an HTTP response into an array with headers and the
-content body. The returned array may look simliar to the following example:
-<?php
array(
0 => array(
'Response Status' => '200 Ok',
'Content-Type' => 'text/plain',
'Content-Language' => 'en-US'
),
1 => "Hello World!"
);
?>
-
+content body. The returned array may look simliar to the following example:
+<?php
array(
0 => array(
'Response Status' => '200 Ok',
'Content-Type' => 'text/plain',
'Content-Language' => 'en-US'
),
1 => "Hello World!"
);
?>
+
array http_parse_headers(string header)
array http_get_request_headers(void)
- +Get a list of incoming HTTP headers.
+string http_get_request_body(void)
+Get the raw request body (e.g. POST or PUT data).
+bool http_match_request_header(string header, string value[, bool match_case = false])
+Match an incoming HTTP header.
string http_get(string url[, array options[, array &info]])
Performs an HTTP GET request on the supplied url.
@@ -201,11 +205,10 @@ array where the following keys will be recognized:- redirect: - lastmodified: int, timestamp for If-(Un)Modified-Since header
- timeout: int, seconds the request may take
- connecttimeout: int, seconds the connect may take
- - onprogress: mixed, progress callback
- - ondebug: mixed, debug callbackThe optional third parameter will be filled with some additional information
-in form af an associative array, if supplied, like the following example:
-<?php
array (
'effective_url' => 'http://localhost',
'response_code' => 403,
'total_time' => 0.017,
'namelookup_time' => 0.013,
'connect_time' => 0.014,
'pretransfer_time' => 0.014,
'size_upload' => 0,
'size_download' => 202,
'speed_download' => 11882,
'speed_upload' => 0,
'header_size' => 145,
'request_size' => 62,
'ssl_verifyresult' => 0,
'filetime' => -1,
'content_length_download' => 202,
'content_length_upload' => 0,
'starttransfer_time' => 0.017,
'content_type' => 'text/html; charset=iso-8859-1',
'redirect_time' => 0,
'redirect_count' => 0,
'private' => '',
'http_connectcode' => 0,
'httpauth_avail' => 0,
'proxyauth_avail' => 0,
)
?>
-
+ - onprogress: mixed, progress callbackThe optional third parameter will be filled with some additional information
+in form af an associative array, if supplied, like the following example:@@ -222,116 +225,44 @@ See http_get() for a full list of available options. Returns the HTTP response as string.
+<?php
array (
'effective_url' => 'http://localhost',
'response_code' => 403,
'total_time' => 0.017,
'namelookup_time' => 0.013,
'connect_time' => 0.014,
'pretransfer_time' => 0.014,
'size_upload' => 0,
'size_download' => 202,
'speed_download' => 11882,
'speed_upload' => 0,
'header_size' => 145,
'request_size' => 62,
'ssl_verifyresult' => 0,
'filetime' => -1,
'content_length_download' => 202,
'content_length_upload' => 0,
'starttransfer_time' => 0.017,
'content_type' => 'text/html; charset=iso-8859-1',
'redirect_time' => 0,
'redirect_count' => 0,
'private' => '',
'http_connectcode' => 0,
'httpauth_avail' => 0,
'proxyauth_avail' => 0,
)
?>
+
See http_get() for a full list of available options.string http_put_file(string url, string file[, array options[, array &info]])
- +Performs an HTTP PUT request, uploading file.
+Returns the HTTP response as string.
+See http_get() for a full list of available options.string http_put_stream(string url, resource stream[, array options[, array &info]])
- -bool http_request()
-}}} */
+
-
-/* {{{ proto long http_request_method_register(string method)Performs an HTTP PUT request, uploading stream.
+
+Returns the HTTP response as string.
+See http_get() for a full list of available options.long http_request_method_register(string method)
+Register a custom request method.
bool http_request_method_unregister(mixed method)
- +Unregister a previously registered custom request method.
long http_request_method_exists(mixed method)
- +Check if a request method is registered (or available by default).
string http_request_method_name(long method)
- +Get the literal string representation of a standard or registered request method.
bool http_auth_basic(string user, string pass[, string realm = "Restricted"])
-Example:
-<?php
if (!http_auth_basic('mike', 's3c|r3t')) {
die('<h1>Authorization failed!</h1>');
}
?>
-
+Example:
+<?php
if (!http_auth_basic('mike', 's3c|r3t')) {
die('<h1>Authorization failed!</h1>');
}
?>
+
bool http_auth_basic_cb(mixed callback[, string realm = "Restricted"])
-Example:
-<?php
function auth_cb($user, $pass)
{
global $db;
$query = 'SELECT pass FROM users WHERE user='. $db->quoteSmart($user);
if (strlen($realpass = $db->getOne($query)) {
return $pass === $realpass;
}
return false;
}
if (!http_auth_basic_cb('auth_cb')) {
die('<h1>Authorization failed</h1>');
}
?>
-
+Example:
+<?php
function auth_cb($user, $pass)
{
global $db;
$query = 'SELECT pass FROM users WHERE user='. $db->quoteSmart($user);
if (strlen($realpass = $db->getOne($query)) {
return $pass === $realpass;
}
return false;
}
if (!http_auth_basic_cb('auth_cb')) {
die('<h1>Authorization failed</h1>');
}
?>
+
string http_build_query(mixed formdata [, string prefix[, string arg_separator]])
Generates a form-encoded query string from an associative array or object.
-http_methods.c
-HttpResponse
-void HttpResponse::__construct(bool cache, bool gzip)
-Instantiates a new HttpResponse object, which can be used to send
-
-any data/resource/file to an HTTP client with caching and multiple
-ranges/resuming support.
-
-NOTE: GZIPping is not implemented yet.bool HttpResponse::setCache(bool cache)
-Whether it sould be attempted to cache the entitity.
-
-This will result in necessary caching headers and checks of clients
-"If-Modified-Since" and "If-None-Match" headers. If one of those headers
-matches a "304 Not Modified" status code will be issued.
-
-NOTE: If you're using sessions, be shure that you set session.cache_limiter
-to something more appropriate than "no-cache"!bool HttpResponse::getCache()
-Get current caching setting.
-bool HttpResponse::setGzip(bool gzip)
-Enable on-thy-fly gzipping of the sent entity. NOT IMPLEMENTED YET.
-bool HttpResponse::getGzip()
-Get current gzipping setting.
-bool HttpResponse::setCacheControl(string control[, bool raw = false])
-Set a custom cache-control header, usually being "private" or "public"; if
-
-$raw is set to true the header will be sent as-is.string HttpResponse::getCacheControl()
-Get current Cache-Control header setting.
-bool HttpResponse::setContentType(string content_type)
-Set the content-type of the sent entity.
-string HttpResponse::getContentType()
-Get current Content-Type header setting.
-bool HttpResponse::setContentDisposition(string filename[, bool inline = false])
-Set the Content-Disposition of the sent entity. This setting aims to suggest
-
-the receiveing user agent how to handle the sent entity; usually the client
-will show the user a "Save As..." popup.array HttpResponse::getContentDisposition()
-Get current Content-Disposition setting.
-Will return an associative array like:array(-
- 'filename' => 'foo.bar',
- 'inline' => false
-)
-bool HttpResponse::setETag(string etag)
-Set a custom ETag. Use this only if you know what you're doing.
-string HttpResponse::getETag()
-Get the previously set custom ETag.
-void HttpResponse::setThrottleDelay(double seconds)
- -double HttpResponse::getThrottleDelay()
- -void HttpResponse::setSendBuffersize(long bytes)
- -long HttpResponse::getSendBuffersize()
- -bool HttpResponse::setData(string data)
-Set the data to be sent.
-string HttpResponse::getData()
-Get the previously set data to be sent.
-bool HttpResponse::setStream(resource stream)
-Set the resource to be sent.
-resource HttpResponse::getStream()
-Get the previously set resource to be sent.
-bool HttpResponse::setFile(string file)
-Set the file to be sent.
-string HttpResponse::getFile()
-Get the previously set file to be sent.
-bool HttpResponse::send()
-Finally send the entity.
-
-Example:-
-<?php
$r = new HttpResponse(true);
$r->setFile('../hidden/contract.pdf');
$r->setContentType('application/pdf');
$r->send();
?>
-
-
-
-static HttpMessage HttpMessage::fromString(string raw_message)
-Create an HttpMessage object from a string.
+http_message_object.c
HttpMessage
void HttpMessage::__construct([string message])
Instantiate a new HttpMessage object.
+static HttpMessage HttpMessage::fromString(string raw_message)
+Create an HttpMessage object from a string.
string HttpMessage::getBody()
Get the body of the parsed Message.
array HttpMessage::getHeaders()
@@ -373,6 +304,8 @@ Returns false if version is invalid (1.0 and 1.1).Send the Message according to its type as Response or Request.
string HttpMessage::toString([bool include_parent = true])
Get the string representation of the Message.
+
+http_request_object.c
HttpRequest
void HttpRequest::__construct([string url[, long request_method = HTTP_GET]])
Instantiate a new HttpRequest object which can be used to issue HEAD, GET
@@ -403,9 +336,9 @@ and POST (including posting files) HTTP requests.Get previously set cookies.
void HttpRequest::unsetCookies()
-bool HttpRequest::setURL(string url)
+bool HttpRequest::setUrl(string url)
Set the request URL.
-string HttpRequest::getUrl()
+string HttpRequest::getUrl()
Get the previously set request URL.
bool HttpRequest::setMethod(long request_method)
Set the request methods; one of the HTTP_HEAD, HTTP_GET or
@@ -444,11 +377,23 @@ Affects only POST requests.bool HttpRequest::addPostFile(string name, string file[, string content_type = "application/x-octetstream"])
Add a file to the POST request.
+
Affects only POST requests.bool HttpRequest::setPostFiles(array post_files)
+Set files to post.
+Overwrites previously set post files.
+Affects only POST requests.array HttpRequest::getPostFiles()
Get all previously added POST files.
void HttpRequest::unsetPostFiles()
Unset the POST files list.
+
Affects only POST requests.bool HttpRequest::SetPutFile(string file)
+Set file to put.
+
+Affects only PUT requests.string HttpRequest::getPutFile()
+Get previously set put file.
+void HttpRequest::unsetPutFile()
+Unset file to put.
+Affects only PUT requests.array HttpRequest::getResponseData()
Get all response data after the request has been sent.
mixed HttpRequest::getResponseHeader([string name])
@@ -464,20 +409,140 @@ Affects only POST requests. See http_get() for a full list of returned info.HttpMessage HttpRequest::getResponseMessage()
Get the full response as HttpMessage object.
+HttpMessage HttpRequest::getRequestMessage()
+Get sent HTTP message.
bool HttpRequest::send()
Send the HTTP request.
-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;
}
?>
-
-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');
if ($r->send()) {
echo $r->getResponseBody();
}
?>
-
+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;
}
?>
+
+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');
if ($r->send()) {
echo $r->getResponseBody();
}
?>
+
+
+
+
+http_requestpool_object.c
+HttpRequestPool
+void HttpRequestPool::__construct([HttpRequest request[, ...]])
+Instantiate a new HttpRequestPool object. An HttpRequestPool is
+able to send several HttpRequests in parallel.
+
+Example:+
+<?php
try {
$pool = new HttpRequestPool(
new HttpRequest('http://www.google.com/', HTTP_HEAD),
new HttpRequest('http://www.php.net/', HTTP_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;
}
?>
+
+
+
+void HttpRequestPool::__destruct()
+Clean up HttpRequestPool object.
+void HttpRequestPool::reset()
+Detach all attached HttpRequest objects.
+bool HttpRequestPool::attach(HttpRequest request)
+Attach an HttpRequest object to this HttpRequestPool.
+
+NOTE: set all options prior attaching!bool HttpRequestPool::detach(HttpRequest request)
+Detach an HttpRequest object from this HttpRequestPool.
+bool HttpRequestPool::send()
+Send all attached HttpRequest objects in parallel.
+protected bool HttpRequestPool::socketSend()
+Usage:
+
+<?php
while ($pool->socketSend()) {
do_something_else();
if (!$pool->socketSelect()) {
die('Socket error');
}
}
$pool->socketRead();
?>
+
+
+
+protected bool HttpRequestPool::socketSelect()
+See HttpRequestPool::socketSend().
+protected void HttpRequestPool::socketRead()
+See HttpRequestPool::socketSend().
+bool HttpRequestPool::valid()
+Implements Iterator::valid().
+HttpRequest HttpRequestPool::current()
+Implements Iterator::current().
+long HttpRequestPool::key()
+Implements Iterator::key().
+void HttpRequestPool::next()
+Implements Iterator::next().
+void HttpRequestPool::rewind()
+Implements Iterator::rewind().
+
+http_response_object.c
+static bool HttpResponse::setCache(bool cache)
+Whether it sould be attempted to cache the entitity.
+
+This will result in necessary caching headers and checks of clients
+"If-Modified-Since" and "If-None-Match" headers. If one of those headers
+matches a "304 Not Modified" status code will be issued.
+
+NOTE: If you're using sessions, be shure that you set session.cache_limiter
+to something more appropriate than "no-cache"!static bool HttpResponse::getCache()
+Get current caching setting.
+static bool HttpResponse::setGzip(bool gzip)
+Enable on-thy-fly gzipping of the sent entity. NOT IMPLEMENTED YET.
+static bool HttpResponse::getGzip()
+Get current gzipping setting.
+static bool HttpResponse::setCacheControl(string control[, long max_age = 0])
+Set a custom cache-control header, usually being "private" or "public";
+
+The max_age parameter controls how long the cache entry is valid on the client side.static string HttpResponse::getCacheControl()
+Get current Cache-Control header setting.
+static bool HttpResponse::setContentType(string content_type)
+Set the content-type of the sent entity.
+static string HttpResponse::getContentType()
+Get current Content-Type header setting.
+static bool HttpResponse::setContentDisposition(string filename[, bool inline = false])
+Set the Content-Disposition of the sent entity. This setting aims to suggest
+
+the receiveing user agent how to handle the sent entity; usually the client
+will show the user a "Save As..." popup.static string HttpResponse::getContentDisposition()
+Get current Content-Disposition setting.
+static bool HttpResponse::setETag(string etag)
+Set a custom ETag. Use this only if you know what you're doing.
+static string HttpResponse::getETag()
+Get the previously set custom ETag.
+static void HttpResponse::setThrottleDelay(double seconds)
+ +static double HttpResponse::getThrottleDelay()
+ +static void HttpResponse::setBufferSize(long bytes)
+ +static long HttpResponse::getBufferSize()
+ +static bool HttpResponse::setData(string data)
+Set the data to be sent.
+static string HttpResponse::getData()
+Get the previously set data to be sent.
+static bool HttpResponse::setStream(resource stream)
+Set the resource to be sent.
+static resource HttpResponse::getStream()
+Get the previously set resource to be sent.
+static bool HttpResponse::setFile(string file)
+Set the file to be sent.
+static string HttpResponse::getFile()
+Get the previously set file to be sent.
+static bool HttpResponse::send([bool clean_ob = true])
+Finally send the entity.
+
+Example:+
+<?php
HttpResponse::setCache(true);
HttpResponse::setContentType('application/pdf');
HttpResponse::setContentDisposition("$user.pdf", false);
HttpResponse::setFile('sheet.pdf');
HttpResponse::send();
?>
+
+
+
+static void HttpResponse::capture()
+Capture script output.
+
+Example:
+<?php
HttpResponse::setCache(true);
HttpResponse::capture();
// script follows
?>
+
-Generated at: Wed, 25 May 2005 19:01:02 +0200
+Generated at: Mon, 01 Aug 2005 09:46:36 +0200