X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-http;a=blobdiff_plain;f=docs%2Fexamples%2Ftutorial.txt;fp=docs%2Fexamples%2Ftutorial.txt;h=0000000000000000000000000000000000000000;hp=8d8998d0a05a5df8c588e85b38a60507d31ec3c9;hb=87db9817d428282792c8146d9c2ae9748ebf6f1e;hpb=7a5c865f6faf8b1b6c91735e9d3b040449ea74ba diff --git a/docs/examples/tutorial.txt b/docs/examples/tutorial.txt deleted file mode 100644 index 8d8998d..0000000 --- a/docs/examples/tutorial.txt +++ /dev/null @@ -1,175 +0,0 @@ - -A Beginners Tutorial --------------------- -$Revision$ - - -- GET Queries - - The HttpRequest class can be used to execute any HTTP request method. - The following example shows a simple GET request where a few query - parameters are supplied. Additionally potential cookies will be - read from and written to a file. - -setOptions( - array( 'cookiestore' => 'google.txt', - ) -); - -$r->setQueryData( - array( 'q' => '+"pecl_http" -msg -cvs -list', - 'hl' => 'de' - ) -); - -// HttpRequest::send() returns an HttpMessage object -// of type HttpMessage::TYPE_RESPONSE or throws an exception -try { - print $r->send()->getBody(); -} catch (HttpException $e) { - print $e; -} -?> - -- Multipart Posts - - The following example shows an multipart POST request, with two form - fields and an image that's supposed to be uploaded to the server. - It's a bad habit as well as common practice to issue a redirect after - an received POST request, so we'll allow a redirect by enabling the - redirect option. - -setOptions( - array( 'cookies' => array('MyCookie' => 'has a value'), - 'redirect' => true, - ) -); - -// common form data -$r->setPostFields( - array( 'name' => 'Mike', - 'mail' => 'mike@php.net', - ) -); -// add the file to post (form name, file name, file type) -touch('profile.jpg'); -$r->addPostFile('image', 'profile.jpg', 'image/jpeg'); - -try { - print $r->send()->getBody(); -} catch (HttpException $e) { - print $e; -} -?> - -- Parallel Requests - - It's possible to execute several HttpRequests in parallel with the - HttpRequestPool class. HttpRequests to send, do not need to perform - the same request method, but can only be attached to one HttpRequestPool - at the same time. - -attach(new HttpRequest('http://pear.php.net', HTTP_METH_HEAD)); - $p->attach(new HttpRequest('http://pecl.php.net', HTTP_METH_HEAD)); -} catch (HttpException $e) { - print $e; - exit; -} - -try { - $p->send(); - // HttpRequestPool implements an iterator over attached HttpRequest objects - foreach ($p as $r) { - echo "Checking ", $r->getUrl(), " reported ", $r->getResponseCode(), "\n"; - } -} catch (HttpException $e) { - print $e; -} -?> - -- Parallel Requests? - - You can use a more advanced approach by using the protected interface of - the HttpRequestPool class. This allows you to perform some other tasks - while the requests are executed. - -socketPerform(); $i++) { - $i % 10 or print "."; - if (!$this->socketSelect()) { - throw new HttpException("Socket error!"); - } - } - print "\nDone!\n"; - } -} - -try { - foreach (new Pool as $r) { - echo "Checking ", $r->getUrl(), " reported ", $r->getResponseCode(), "\n"; - } -} catch (HttpException $ex) { - print $e; -} -?> - -- Cached Responses - - One of the main key features of HttpResponse is HTTP caching. HttpResponse - will calculate an ETag based on the http.etag_mode INI setting as well as - it will determine the last modification time of the sent entity. It uses - those two indicators to decide if the cache entry on the client side is - still valid and will emit an "304 Not Modified" response if applicable. - - - -- Bandwidth Throttling - - HttpResponse supports a basic throttling mechanism, which is enabled by - setting a throttle delay and a buffer size. PHP will sleep the specified - amount of seconds after each sent chunk of specified bytes. - -