HTTP_Request2, keep-alive and re-using request objects

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

HTTP_Request2, keep-alive and re-using request objects

Christian Weiske
Hi,


HTTP_Request2 supports keep-alive in HTTP requests.
The question is now how to use it.

The following naive code does not use it:

<?php
$req1 = new HTTP_Request2('http://example.org/1.htm');
$res1 = $req1->send();

$req2 = new HTTP_Request2('http://example.org/1.htm');
$res2 = $req2->send();
?>

As far as I see, the keep-alive support is implemented in the adapter.
This means that I could create the adapter myself and share it:

<?php
$adapter = new HTTP_Request2_Adapter_Socket();
$req1 = new HTTP_Request2('http://example.org/1.htm');
$req1->setAdapter($adapter);
$res1 = $req1->send();

$req2 = new HTTP_Request2('http://example.org/1.htm');
$req2->setAdapter($adapter);
$res2 = $req2->send();
?>

This forces me to choose the adapter myself, which I might not want.


Another option is to re-use the request object:

<?php
$req = new HTTP_Request2('http://example.org/1.htm');
$res1 = $req->send();

$req->setURL('http://example.org/1.htm');
$res2 = $req->send();
?>

This works, but the issue I have here are headers, the request body and
POST data. They are - as far as I see - not reset between requests.

Now my questions:

1. Is the observation about not-resetting headers between requests correct?
2. Did I forget some way to do keep-alive?
3. What's the best way to use keep-alive with HTTP_Request2?


--
Regards/Mit freundlichen Grüßen
Christian Weiske

-=≡ Geeking around in the name of science since 1982 ≡=-

--
PEAR General Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply | Threaded
Open this post in threaded view
|

Re: HTTP_Request2, keep-alive and re-using request objects

Christian Weiske
Hi Christian,


> HTTP_Request2 supports keep-alive in HTTP requests.
> The question is now how to use it.
>
> The following naive code does not use it:
>
> <?php
> $req1 = new HTTP_Request2('http://example.org/1.htm');
> $res1 = $req1->send();
>
> $req2 = new HTTP_Request2('http://example.org/1.htm');
> $res2 = $req2->send();
> ?>

The code *does* indeed use it.
In the socket adapter, the connection list is static and thus
automatically shared.

--
Regards/Mit freundlichen Grüßen
Christian Weiske

-=≡ Geeking around in the name of science since 1982 ≡=-

--
PEAR General Mailing List (http://pear.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php