2 title: HttpRequestDataShare
8 There are some news to talk about development of
9 [pecl/http](http://pecl.php.net/package/pecl_http).
11 I recently implemented an interface to the [curl-
12 share](http://curl.haxx.se/libcurl/c/libcurl-share.html) functionality in form
13 of an HttpRequestDataShare class.
15 This is what [reflection](http://php.net/reflection) will tell you about it:
18 mike@honeybadger:~/build/php-5.2-debug$ cli --rc HttpRequestDataShare
19 Class [ <internal:http> class HttpRequestDataShare implements Countable ] {
24 - Static properties [1] {
25 Property [ private static $instance ]
28 - Static methods [1] {
29 Method [ <internal> static public method singleton ] {
32 Parameter #0 [ <optional> $global ]
38 Property [ <default> public $cookie ]
39 Property [ <default> public $dns ]
40 Property [ <default> public $ssl ]
41 Property [ <default> public $connect ]
45 Method [ <internal, dtor> public method __destruct ] {
51 Method [ <internal, prototype Countable> public method count ] {
57 Method [ <internal> public method attach ] {
60 Parameter #0 [ <required> HttpRequest $request ]
64 Method [ <internal> public method detach ] {
67 Parameter #0 [ <required> HttpRequest $request ]
71 Method [ <internal> public method reset ] {
80 Using this class, you can save a fair amount of time with name lookups which
81 the following example shows:
83 $s = HttpRequestDataShare::singleton(true);
85 for ($i = 0; $i < 10; ++$i) {
86 $r = new HttpRequest("http://www.google.com/");
89 printf("%0.6fn", $r->getResponseInfo("namelookup_time"));
94 Executing this script without dns data sharing enabled gives the following
97 mike@honeybadger:~/build/php-5.2-debug$ cli -d"http.request.datashare.dns=0"
98 ~/devel/http_rshare.php
99 HttpRequestDataShare Object
118 ...and with dns data sharing enabled:
120 mike@honeybadger:~/build/php-5.2-debug$ cli -d"http.request.datashare.dns=1"
121 ~/devel/http_rshare.php
122 HttpRequestDataShare Object
143 You can either use a per-process global datashare object created with
144 HttpRequestDataShare::singleton(true) or different instances for your
145 HttpRequest objects. Note that dns datasharing is used autmagically for
146 HttpRequestPool requests. Currently libcurl has implemented cookie and dns
147 data sharing only, trying to enable ssl session or connect sharing will raise
150 Be sure to try it out; either directly from CVS or the next release, probably