我有两个文件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