简体   繁体   中英

ob_start(); in php?

When using on_start() does it make any difference to do,

// ENABLE GZIP COMPRESSION
ob_start();
ob_start('ob_gzhandler');

Or is this exactly the same,

// ENABLE GZIP COMPRESSION
ob_start('ob_gzhandler');

I ask as with the first example my website seems to speed up a bit.

Thanks

You should do either:

ob_start();

or:

ob_start('ob_gzhandler');

But not both. You can check $_SERVER['HTTP_ACCEPT_ENCODING'] to see if the user agent accepts gzip encodings:

if(strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false)
   ob_start('ob_gzhandler');
else
    ob_start();

The first starts two layers of output buffering. Waste of memory.

No difference at all. ob_start() is stackable. Which means the second ob_start() will simply append it's contents to the first ob_start() when flushed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM