I have two files client.php and server.php. The client file send a HTTP request to the server file. The server file can be very slow to process the request so I just want it to answer to the client "OK the request is correct, the result will be sent by email".
But I don't know to make the server close the HTTP request with suitable headers and continue its job. If I specify a timeout of 1 second, I wont't be able to know if the request will be accepted by the server.
So is it possible in PHP ? Do you know how ?
client.php:
<?php
$resource = curl_init();
curl_setopt($resource, CURLOPT_URL, 'http://localhost/server.php');
curl_setopt($resource, CURLOPT_RETURNTRANSFER, true);
curl_setopt($resource, CURLOPT_TIMEOUT, 30);
curl_exec($resource);
server.php
<?php
header('200 OK');
echo 'OK the request is correct, the result will be sent by email';
// How to write the method below?
send_result_to_client();
// Simulates a slow process
sleep(60);
Ok I found the solution. In the function send_result_to_client should seem to :
function send_result_to_client()
{
$myString = '...';
$size = strlen($myString);
header("Content-Length: $size");
header('Connection: close');
flush();
}