我有兩個文件client.php和server.php。 客戶端文件向服務器文件發送HTTP請求。服務器文件處理請求的速度非常慢,所以我只希望它能夠回答客戶端「確定請求是正確的,結果將通過電子郵件發送」。直接從服務器中斷HTTP請求
但我不知道要使服務器關閉具有合適標頭的HTTP請求並繼續其工作。如果我指定1秒的超時時間,則無法知道該請求是否會被服務器接受。
那麼有可能在PHP?你知不知道怎麼 ?
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);
好,我找到了解決辦法。 在功能send_result_to_client有人似乎是:
function send_result_to_client()
{
$myString = '...';
$size = strlen($myString);
header("Content-Length: $size");
header('Connection: close');
flush();
}
好,我找到了解決辦法。我編輯了我原來的帖子。 – 2012-03-07 13:22:30
aaah有道理,很好:) – Manatok 2012-03-07 13:26:24
這是可能的,就像你說的。使用atd(或者Scheduler,或者周圍的任何不同的端口和包裝器)來做到這一點。或者另一個PHP腳本,從crontab運行。 – LSerni 2012-07-05 17:28:01