HTTP_Request2, keep-alive and re-using request objects

From: Date: Fri, 02 Sep 2016 08:00:17 +0000
Subject: HTTP_Request2, keep-alive and re-using request objects
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-32155@lists.php.net to get a copy of this message
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 ≡=-

« previous php.pear.general (#32155) next »