---
layout: page
title: "JavaScript ob_end_flush function"
comments: true
sharing: true
footer: true
alias:
- /functions/view/ob_end_flush:892
- /functions/view/ob_end_flush
- /functions/view/892
- /functions/ob_end_flush:892
- /functions/892
---
<!-- Generated by Rakefile:build -->
A JavaScript equivalent of PHP's ob_end_flush

{% codeblock outcontrol/ob_end_flush.js lang:js https://raw.github.com/kvz/phpjs/master/functions/outcontrol/ob_end_flush.js raw on github %}
function ob_end_flush () {
  // http://kevin.vanzonneveld.net
  // +   original by: Brett Zamir (http://brett-zamir.me)
  // *     example 1: ob_end_flush();
  // *     returns 1: true

  var PHP_OUTPUT_HANDLER_START = 1,
    PHP_OUTPUT_HANDLER_END = 4;

  this.php_js = this.php_js || {};
  var obs = this.php_js.obs;

  if (!obs || !obs.length) {
    return false;
  }
  var flags = 0,
    ob = obs[obs.length - 1],
    buffer = ob.buffer;
  if (ob.callback) {
    if (!ob.status) {
      flags |= PHP_OUTPUT_HANDLER_START;
    }
    flags |= PHP_OUTPUT_HANDLER_END;
    ob.status = 2;
    buffer = ob.callback(buffer, flags);
  }
  obs.pop();
  if (obs.length) {
    ob = obs[obs.length - 1];
    ob.buffer += buffer;
  } else {
    this.echo(buffer);
  }

  return true;
}
{% endcodeblock %}

 - [view on github](https://github.com/kvz/phpjs/blob/master/functions/outcontrol/ob_end_flush.js)
 - [edit on github](https://github.com/kvz/phpjs/edit/master/functions/outcontrol/ob_end_flush.js)

### Example 1
This code
{% codeblock lang:js example %}
ob_end_flush();
{% endcodeblock %}

Should return
{% codeblock lang:js returns %}
true
{% endcodeblock %}


### Other PHP functions in the outcontrol extension
{% render_partial _includes/custom/outcontrol.html %}
