dongsou8980 2016-04-19 01:20
浏览 96
已采纳

Ob_end_flush正在生成常量错误

I am currently working with Server-Sent Events and I am having a strange issue. As the event goes on, through each iteration I am receiving the following error:

ob_end_flush(): failed to delete and flush buffer. No buffer to delete or flush in

My code for the Server-Event Server Side is as follows:

<?php

  require "connect.php";

  session_write_close();

  header("Content-Type: text/event-stream

");

  $savedcount = 0; 
  while (1) {

    // Who's mechanism 
    $query = $mysqli->query("SOME QUERY"); 
    $rowcount = $query->num_rows;

    if ($savedcount != $rowcount) {
       // echo stuff
       $savedcount = $rowcount; // only echo stuff if there is new content
    }

    ob_end_flush();
    flush();
    sleep(2);
  }

?>

I do not completely understand buffers. Also, before you assume that this is terrible practice please know that Server-Sent Events are special. This is a similar script that they show on MDN. For this reason I am not exactly sure why I am continuously receiving these errors.

Suggestions?

  • 写回答

2条回答 默认 最新

  • duanhuan6336 2016-04-19 20:10
    关注

    I have always used this idiom:

    @ob_flush();@flush();
    

    Quoting from p.21 of Data Push Apps With HTML5 SSE: (disclaimer: my book)

    @ is said to be slow. But putting that in context, it adds on the order of 0.01ms to call it twice, as shown here. ... http://git.php.net/?p=php-src.git;a=blob;f=sapi/apache2handler/sapi_apache2.c#l290 suggests flush() can never throw an error, so @ on flush() could be dropped, just leaving it on @ob_flush().

    http://git.php.net/?p=php-src.git;a=blob;f=main/output.c#l1328 shows the two E_NOTICEs that ob_flush() can give.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。