1

Is there a way to pool or reuse HTTP connections with PHP's curl client? I already found Persistent/keepalive HTTP with the PHP Curl library?, but it only allows connection reuse on the same handle, and there isn't a good way to persist handles between multiple fastcgi PHP calls, and that's probably a bad idea because the handle might never be closed.

The only solution I found was routing the requests through a proxy that does connection pooling.

David Ehrmann
  • 7,366
  • 2
  • 31
  • 40
  • Interesting question, can you clarify what you meant by `multiple fastcgi PHP calls` ? – Mostafa Berg Mar 25 '19 at 21:06
  • Sure; and it changes what @lars-stegelitz was answering. What I really meant is that within a php script, is there a way to reuse HTTP connections across script invocations. In this case, it's a web page, so fastcgi (or mod-php) will make the PHP call. – David Ehrmann Mar 25 '19 at 21:21
  • I see, if I understand you correctly, itsn't this something `curl_multi_*` methods can fix for you? – Mostafa Berg Mar 25 '19 at 21:24
  • @MostafaBerg sadly, no, because there isn't a way to save (or release) handles or multi-handles between calls. – David Ehrmann Mar 25 '19 at 22:13
  • Of course, I misunderstood you!, I thought method invocations, not script invocations. I'll look around and update if I have any findings, I haven't come across that use case before – Mostafa Berg Mar 25 '19 at 22:17
  • I'm surprised it's not a more common use case. If this were actual `php` command line calls, I get how it'd be unusual, from when it's for a web page, it seems like sharing HTTP connections between Apache/Nginx requests would be a normal thing to do. – David Ehrmann Mar 25 '19 at 22:23
  • I meant that as in "PHP is stateless", so this use case is not really something natural for PHP, but I'm sure there's a way, but how uncommon it is, makes it kind of scary to go down that path, I'll still be researching though :) – Mostafa Berg Mar 25 '19 at 22:30
  • @DavidEhrmann Have you found the solution? I've faced the similar problem and the only solution right now is using local proxy that keeps connections opened. Thanks! – Kirzilla Aug 19 '20 at 21:06
  • 1
    @Kirzilla Nope; I did exactly that, use Apache/Nginx/whatever as a proxy. – David Ehrmann Aug 20 '20 at 01:48

1 Answers1

0

That would depend on the Webserver and the fast-CGI configuration.

Should be possible with fast-CGI, but the webserver has to support it as well.

Read this SO article, which has a good explanation what multiplexing can do for you

fastcgi multiplexing?

Honk der Hase
  • 2,459
  • 1
  • 14
  • 26