I would say using pfsockopen()to create a permanent connection would do the trick. You can open the socket on the HTTP API server, and then make several petitions and close the socket when the page finishes loading.
<?php
$host = "protocol://your-api-hostname.com/";
$uri = "/your/api/location";
$port = 80;
$socket = pfsockopen ($host, $port, $errno, $errstr, 0);
if (!$socket) {
echo $errno. " - " . $errstr;
} else {
fputs ($socket, $request1);
fputs ($socket, $request2);
$i = 0;
$a = array();
while (!feof($socket)) {
$a[$i] = fgets($socket);
$i++;
}
fclose($socket);
I do not know if this is exactly what you need, but it offers more options than cURL.
source
share