X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;f=docs%2Ffunctions.html;h=0e53c616ce4ffb26a736e14107fef50907ba24d4;hb=f0bcc141e62c022101d8d19c1d73e7b9ae41d0e9;hp=69a7e63dcba18dbc7358a28a844c39ca2a30135e;hpb=af89101537efd3a5439953a71dc5aef9f2b3daf0;p=m6w6%2Fext-http diff --git a/docs/functions.html b/docs/functions.html index 69a7e63..0e53c61 100644 --- a/docs/functions.html +++ b/docs/functions.html @@ -81,7 +81,7 @@ 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.

+

Returns the absolute URI as string on success or false on failure.

Examples:


<?php
$uri 
http_build_uri("page.php""https"NULL488);
?>

@@ -113,6 +113,19 @@ if none match.

<?php
$charsets 
= array(
        
'iso-8859-1'// default
        
'iso-8859-2',
        
'iso-8859-15',
        
'utf-8'
);

$pref http_negotiate_charset($charsets$result);

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');
}

print_r($result);
?>

+

string http_negotiate_ctype(array supported[, array &result])

+

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));
?>
+

+

bool http_send_status(int status)

Send HTTP status code.

Expects an HTTP status code as parameter.

@@ -240,7 +253,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/htmlchatset=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/htmlchatset=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] => /
)
?>

array http_get_request_headers(void)

@@ -337,7 +358,7 @@ 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_gzencode(string data[, int level = -1])

+

string http_gzencode(string data[, int level = -1[, int mtime = 0]])

Compress data with the HTTP compatible GZIP encoding.

Expects the first parameter to be a string which contains the data that
should be encoded. Additionally accepts an optional in paramter specifying
@@ -348,7 +369,7 @@ best compression ratio.

Uncompress data compressed with the HTTP compatible GZIP encoding.

Expects a string as parameter containing the compressed data.

Returns the decoded string on success, or NULL on failure.

-

string http_deflate(string data[, int level = -1])

+

string http_deflate(string data[, int level = -1[, bool zlib_header = false]])

Compress data with the HTTP compatible DEFLATE encoding.

Expects the first parameter to be a string containing the data that should
be encoded. Additionally accepts an optional int parameter specifying the
@@ -359,17 +380,6 @@ compression ratio.

Uncompress data compressed with the HTTP compatible DEFLATE encoding.

Expects a string as parameter containing the compressed data.

Returns the decoded string on success, or NULL on failure.

-

string http_compress(string data[, int level = -1])

-

Compress data with the HTTP compatible COMPRESS encoding.

-

Expects the first parameter to be a string containing the data which should
-be encoded. Additionally accepts an optional int parameter specifying the
-compression level, where -1 is default, 0 is no compression and 9 is best
-compression ratio.

-

Returns the encoded string on success, or NULL on failure.

-

string http_uncompress(string data)

-

Uncompress data compressed with the HTTP compatible COMPRESS encoding.

-

Expects a string as parameter containing the compressed data.

-

Returns the decoded string on success, or NULL on failure.

int http_support([int feature = 0])

Check for feature that require external libraries.

Accpepts an optional in parameter specifying which feature to probe for.
@@ -384,8 +394,6 @@ all supported features that depend on external libraries.

and SSL requests can be issued
  • HTTP_SUPPORT_ENCODINGS: whether ext/http was linked against zlib,
    and compressed HTTP responses can be decoded
    -
  • HTTP_SUPPORT_MHASHETAGS: whether ext/http was linked against libmhash,
    - and ETags can be generated with the available mhash algorithms
  • HTTP_SUPPORT_MAGICMIME: whether ext/http was linked against libmagic,
    and the HttpResponse::guessContentType() method is usable

    @@ -480,6 +488,15 @@ This provides limited functionality compared to HttpRequest and HttpResponse.

    Accepts a bool parameter which specifies whether the returned string
    should also contain any parent messages.

    Returns the full message as string.

    +

    int HttpMessage::count()

    +

    Implements Countable.

    +

    Returns the number of parent messages + 1.

    +

    string HttpMessage::serialize()

    +

    Implements Serializable.

    +

    Returns the serialized representation of the HttpMessage.

    +

    void HttpMessage::unserialize(string serialized)

    +

    Implements Serializable.

    +

    Re-constructs the HttpMessage based upon the serialized string.


    http_request_object.c

    HttpRequest

    @@ -549,7 +566,7 @@ pairs to add.

    bool HttpRequest::setMethod(int request_method)

    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.

    +In PHP 5.1+ HttpRequest::METH_*, otherwise the HTTP_METH_* constants can be used.

    Returns TRUE on success, or FALSE on failure.

    int HttpRequest::getMethod()

    Get the previously set request method.

    @@ -697,6 +714,11 @@ cycle.

    references the last received response. Use HttpMessage::getParentMessage()
    to access the data of previously sent requests whithin this request
    cycle.

    +

    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.

    HttpMessage HttpRequest::getHistory()

    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
    @@ -705,20 +727,26 @@ HttpRequest::$recoedHistory to FALSE.

    history.

    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.

    void HttpRequest::clearHistory()

    Clear the history.

    HttpMessage HttpRequest::send()

    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;
    }
    ?>


    @@ -728,10 +756,10 @@ HttpMalformedHeaderException, HttpEncodingException.

    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.

    +object while you're using the implemented Iterator interface.

    Accepts virtual infinite optional parameters each referencing an
    HttpRequest object.

    -

    Throws HttpRequestException, HttpRequestPoolException, HttpInvalidParamException.

    +

    Throws HttpRequestPoolException (HttpRequestException, HttpInvalidParamException).

    Example:


    <?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;
    }
    ?>

    @@ -757,8 +785,7 @@ HttpRequestPool object.

    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:


    @@ -778,6 +805,9 @@ 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.

    @@ -953,6 +983,8 @@ http.cache_log is set.

  • http_negotiate_charset
  • +
  • http_negotiate_content_type +
  • http_send_status
  • http_send_last_modified @@ -987,6 +1019,8 @@ http.cache_log is set.

  • http_parse_headers
  • +
  • http_parse_cookie +
  • http_get_request_headers
  • http_get_request_body @@ -1023,10 +1057,6 @@ http.cache_log is set.

  • http_inflate
  • -
  • http_compress -
  • -
  • http_uncompress -
  • http_support
  • @@ -1053,6 +1083,9 @@ http.cache_log is set.

  • HttpMessage::getParentMessage()
  • HttpMessage::send()
  • HttpMessage::toString()
  • +
  • HttpMessage::count()
  • +
  • HttpMessage::serialize()
  • +
  • HttpMessage::unserialize()
  • @@ -1120,6 +1153,7 @@ http.cache_log is set.

  • HttpRequestPool::key()
  • HttpRequestPool::next()
  • HttpRequestPool::rewind()
  • +
  • HttpRequestPool::count()
  • HttpRequestPool::getAttachedRequests()
  • HttpRequestPool::getFinishedRequests()
  • @@ -1161,7 +1195,7 @@ http.cache_log is set.

    -

    Generated at: Wed, 19 Oct 2005 10:45:25 +0200

    +

    Generated at: Wed, 14 Dec 2005 16:25:48 +0100