1

My PHP server (A) needs to make an http request to another server (B) each time it's called. I'm familiar with the usual use case for using curl in PHP

$ch = curl_init();
curl_setopt_array($ch, $curlOptions);
$responseBody = curl_exec($ch);
$curlErrorCode = curl_errno($ch);
curl_close($ch);

However I'm calling the same server (B) every time. Is there a way to keep the connections between A and B open (keepalive)? Maybe some sort of connection pool?

  • Possible duplicate of [Persistent/keepalive HTTP with the PHP Curl library?](https://stackoverflow.com/questions/972925/persistent-keepalive-http-with-the-php-curl-library) – Martin Zeitler Jan 20 '19 at 07:33
  • ^ this requires the server which receives the request to have keep alive enabled. – Martin Zeitler Jan 20 '19 at 07:35
  • @MartinZeitler thanks for pointing that out. this partially answers the question. But as the answer points out the **cURL handle must be reused**. sounds like i'd have to implement some connection pool class... that initiates the handler once. is there some sort of example or module for this? – binyamin greenberg Jan 20 '19 at 20:12

1 Answers1

0

Implementing socket handling will be great if you want two servers to communicate with each other. http://php.net/manual/en/sockets.examples.php