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

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 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题