这个问题,搜索一下,不知道有多少种回答,但是很多回答的都不准确,我测试总结一下 首先是都认可的要判断connection_status()或connection_aborted(),但是这两个状态的,必须是向前端发送数据后,才能获得,即无法被动获得,只能主动获得 因此判断客户端是
这个问题,搜索一下,不知道有多少种回答,但是很多回答的都不准确,我测试总结一下
首先是都认可的要判断connection_status()或connection_aborted(),但是这两个状态的值,必须是向前端发送数据后,才能获得,即无法被动获得,只能主动获得
因此判断客户端是否中断的方法也就只能是,后端向前端发送数据后,判断connection_status()或connection_aborted()的返回值
<?php ignore_user_abort(true); //如果不忽略,那当下面的flush执行后,程序立即退出 header("Cache-Control: no-cache, must-revalidate"); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); ob_flush(); flush(); //控制浏览器前端不要缓存结果,每次都要重新查询 $maxvid = $_GET["maxvid"]; error_log(date("[Y-m-d H:i:s]")." > "."maxvid: ".$maxvid."\n", 3 , "/usr/local/apache2219/logs/php_log"); $gmworker = new GearmanWorker(); $gmworker->setTimeout(60000); $gmworker->addServer(); $gmworker->addFunction("getmsg", "getmsg"); if ( ($gmworker->work()) && ($gmworker->returnCode() == GEARMAN_SUCCESS) ) { echo $msg; ob_flush(); //必须有,不然是在PHP_BUFFER不会被发送到客户端,也检查不出是否中断 flush(); //必须设置ignore_user_abort(true),不然程序直接退出了,无法再判断连接状态 if ( connection_status() ) { error_log(date("[Y-m-d H:i:s]")." workload(); $result = "OK"; return $result; } ?>
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
What's New in Windows 11 KB5054979 & How to Fix Update Issues
3 weeks agoByDDD
How to fix KB5055523 fails to install in Windows 11?
2 weeks agoByDDD
InZoi: How To Apply To School And University
4 weeks agoByDDD
How to fix KB5055518 fails to install in Windows 10?
2 weeks agoByDDD
Roblox: Dead Rails – How To Summon And Defeat Nikola Tesla
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

Dreamweaver CS6
Visual web development tools

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools
