: PHP는 연결을 일찍 닫습니다. 모든 출력이 완료되면 스크립트는 중단
static public function early_close($output)
{
ignore_user_abort(true);
echo $output;
// Disable gzip compression in apache, as it can result in this request being buffered until it is complete,
// regardless of other settings.
if (function_exists('apache_setenv')) {
apache_setenv('no-gzip', 1);
}
// get the size of the output
$size = ob_get_length();
// send headers to tell the browser to close the connection
header("Content-Length: $size");
header('Connection: close');
header("Content-Encoding: none"); // To disable Apache compressing anything
// IF PHP-FM
// fastcgi_finish_request();
// flush all output
if(ob_get_level() > 0)
{
ob_end_flush();
ob_get_level()? ob_flush():null;
flush();
}
// if you're using sessions, this prevents subsequent requests
// from hanging while the background process executes
if(session_id())
{
session_write_close();
}
}
작품 좋아,하지만이 사건 후 일부 스크립트는 echo'ing 또는 추가하여 하나 (아무것도 출력하는 경우 새 헤더) 스크립트는 해당 지점에서 실행을 중지합니다.
일찍 마감 후 출력 버퍼링을 시작 시도하고 다음을 폐기했지만 작동하지 않습니다
Server::early_close();
ob_start();
heavy_work();
ob_clean();
어떤 아이디어?
PHP 5.3.x
간단한 'die()'버릇이 있습니까? – Anthony
'die()'는 여기서 도움이되지 않습니다. 왜냐하면 서버가'heavy_work' 명령을 받자 마자 클라이언트가 응답해야하기 때문입니다. 클라이언트는 끝내기 위해'heavy_work'를 기다릴 필요가 없습니다. 'Server :: early_close() '대신에'die()'가 실행되면'heavy_work()'가 실행되지 않습니다. –
HTTP 응답이 끝나면 _webserver_ 스레드를 계속 실행하지 마십시오.비동기 작업으로 만듭니다. 기어 맨 (Gearman) 등이 당신을 위해 많은 세부 사항을 처리 할 수 있지만 모든 작업 (대기열)이 수행합니다. – Wrikken