Buffering WordPress rendered page

if( current_user_can('manage_options') )
{
add_action('template_redirect', 'YOURPLUGIN_buffer_start', 0);
}

function YOURPLUGIN_buffer_start() {
add_action('shutdown', 'YOURPLUGIN_buffer_stop', PHP_INT_MAX);
ob_start('YOURPLUGIN_modify_content');
}
function YOURPLUGIN_buffer_stop() {
ob_end_flush();
}
function YOURPLUGIN_modify_content($content) {

$dom = new DomDocument();
$dom->loadHTML($content);
$styles=array();
foreach ($dom->getElementsByTagName('link') as $node)
{
if($node->hasAttribute('rel') && $node->getAttribute('rel')=='stylesheet' )
{
$styles[]=$node->getAttribute("href");
}

}

//modify $content
return serialize($styles).$content;
}

PHP Execution Timeout Digest

Setting the PHP execution limit in php.ini

max_execution_time = 600

===========

Using PHP:

<?php
// set the PHP timelimit to 10 minutes
set_time_limit(600);
?>

<?php ini_set(‘max_execution_time’,600); ?>

 

Override PHP execution time in .htaccess file

  • php_value max_execution_time 600

 

 

 

PHP type comparison tables Digest

Comparisons of $x with PHP functions
Expression gettype() empty() is_null() isset() boolean : if($x)
$x = “”; string TRUE FALSE TRUE FALSE
$x = null; NULL TRUE TRUE FALSE FALSE
var $x; NULL TRUE TRUE FALSE FALSE
$x is undefined NULL TRUE TRUE FALSE FALSE
$x = array(); array TRUE FALSE TRUE FALSE
$x = false; boolean TRUE FALSE TRUE FALSE
$x = true; boolean FALSE FALSE TRUE TRUE
$x = 1; integer FALSE FALSE TRUE TRUE
$x = 42; integer FALSE FALSE TRUE TRUE
$x = 0; integer TRUE FALSE TRUE FALSE
$x = -1; integer FALSE FALSE TRUE TRUE
$x = “1”; string FALSE FALSE TRUE TRUE
$x = “0”; string TRUE FALSE TRUE FALSE
$x = “-1”; string FALSE FALSE TRUE TRUE
$x = “php”; string FALSE FALSE TRUE TRUE
$x = “true”; string FALSE FALSE TRUE TRUE
$x = “false”; string FALSE FALSE TRUE TRUE

Continue reading “PHP type comparison tables Digest”