后台PHP脚本判断客户端是否中断(数据是否真正的发到前端)
这个问题,搜索一下,不知道有多少种回答,但是很多回答的都不准确,我测试总结一下 首先是都认可的要判断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; } ?>

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
