开发者

Is there any measurable overhead using ob_get_contents()?

开发者 https://www.devze.com 2023-02-06 05:15 出处:网络
I want to flush the contents of a WordPress function into a variable using ob_get_contents() but I\'ve heard that there is sometimes overhead associated with it. Ha开发者_JAVA百科s anyone had any actu

I want to flush the contents of a WordPress function into a variable using ob_get_contents() but I've heard that there is sometimes overhead associated with it. Ha开发者_JAVA百科s anyone had any actual experience measuring overhead of this function or thoughts on its cost?


The overhead using output buffering is too insignificant to make a measurable difference - especially in simple WordPress functions.

$start = microtime();
//output buffering script
$stop = microtime();

$timeran = $stop - $start //time it took to run script in MICRO (not milli) seconds


Since ob_get_contents just needs to copy its internal buffers into a new string object, there is actually very little overhead. However, if your internal buffer is huge(measured in MB), this could be problematic. Your WordPress function is likely to be at the other end of the spectrum unless it's outputting zip or image files, so using ob_get_contents will be pretty fast.

0

精彩评论

暂无评论...
验证码 换一张
取 消