How to determine wether ob_start(); has been called already

后端 未结 4 1463
误落风尘
误落风尘 2021-02-19 05:42

I use output buffering for gzip compression and access to what was put out before in a PHP script:

if(!ob_start(\"ob_gzhandler\")) ob_start();

相关标签:
4条回答
  • 2021-02-19 06:19

    ob_get_level returns the number of active output control handlers and ob_list_handlers returns a lift of those handlers. So you could do this:

    if (!in_array('ob_gzhandler', ob_list_handlers())) {
        ob_start('ob_gzhandler');
    } else {
        ob_start();
    }
    

    Although in general you can call ob_start any number of times you want, using ob_gzhandler as handler cannot as you would compress already compressed data.

    0 讨论(0)
  • 2021-02-19 06:22
    if (ob_get_level())
        echo "ob already started";
    
    0 讨论(0)
  • 2021-02-19 06:36

    What about using it this way?

    if (ob_get_level() == 0) ob_start();

    0 讨论(0)
  • 2021-02-19 06:43

    General:

    if (ob_get_status())  {
      // ob started
    }
    

    More specific

    $status = ob_get_status();
    if ($status['name']=='ob_gzhandler') {
     // ob named ob_gzhandler started
    }
    
    0 讨论(0)
提交回复
热议问题