I've a PHP script that need Close connection after return data, but continue executing:
<?php
// Some code
ob_start();
echo $data;
header("Content-type: application/soap+xml;charset=UTF-8
");
header("Content-Length: " . ob_get_length() . "
");
header("Content-Encoding: none
");
header("Connection: close
");
// Print buffer
ob_end_flush();
ob_flush();
flush();
// Close connection
// Some code, continue executing
?>
It's work with some clients, but I need to call sometimes with an other PHP script
<?php
// Some code
$connection = @fsockopen($url['host'], $url['port'], $errno, $errstr);
if (!$connection) {
throw new Exception('');
}
fputs($connection, "POST {$url['path']} HTTP/1.1
");
fputs($connection, "Host: {$url['host']}
");
fputs($connection, "Content-type: text/xml;charset=UTF-8
");
fputs($connection, "SOAPAction: \"{$soapaction}\"
");
fputs($connection, "Content-Length: " . strlen($request) . "
");
fputs($connection, "Content-Encoding: none
");
fputs($connection, "Connection: close
");
fputs($connection, $request);
$respponse = '';
while(!feof($connection)) {
// receive the results of the request
$response .= fgets($connection, 512);
}
// some code
?>
The problem is: fsockopen doesn't close connection when receive the data, only when all first scripts ends.
The only idea I have, it is check the length and close manual when the data is received.