precache comments done, tests done; separated admin part for commands added
This commit is contained in:
parent
b5cde93bee
commit
67b9d0b3f6
3 changed files with 132 additions and 18 deletions
|
@ -26,6 +26,7 @@ Supports PHP Memcached, PHP Memcache and APC as storage engines, subdomain and d
|
||||||
* pingback HTTP header preservation
|
* pingback HTTP header preservation
|
||||||
* (optional) talkative log for troubleshooting
|
* (optional) talkative log for troubleshooting
|
||||||
* multiple memcached upstream support
|
* multiple memcached upstream support
|
||||||
|
* possibility of precaching ( requires permalinks )
|
||||||
|
|
||||||
Many thanks for supporters, testers & bug reporters: [Eric Gilette](http://www.ericgillette.com/ "Eric Gilette"); [doconeill](http://wordpress.org/support/profile/doconeill "doconeill"); [Mark Costlow](mailto:cheeks@swcp.com "Mark Costlow").
|
Many thanks for supporters, testers & bug reporters: [Eric Gilette](http://www.ericgillette.com/ "Eric Gilette"); [doconeill](http://wordpress.org/support/profile/doconeill "doconeill"); [Mark Costlow](mailto:cheeks@swcp.com "Mark Costlow").
|
||||||
|
|
||||||
|
@ -87,8 +88,8 @@ Please post feature requests to [WP-FFPC feature request topic](http://wordpress
|
||||||
= 1.1 =
|
= 1.1 =
|
||||||
*under development*
|
*under development*
|
||||||
|
|
||||||
* added validate caching "noob" method: HTML comment option for cache engine & generation before closing "body" tag
|
* HTML comment option for displaying cache info before closing "body" tag ( a.k.a make sure it works "noob" method )
|
||||||
* pre-cache possibility
|
* precache engine
|
||||||
* bugfix for status check ( there were situations where the status was not updated correctly )
|
* bugfix for status check ( there were situations where the status was not updated correctly )
|
||||||
|
|
||||||
= 1.0 =
|
= 1.0 =
|
||||||
|
|
|
@ -132,3 +132,63 @@
|
||||||
background-image: linear-gradient(to top,#ececec,#f9f9f9);
|
background-image: linear-gradient(to top,#ececec,#f9f9f9);
|
||||||
outline: none;
|
outline: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.button-warning {
|
||||||
|
display: inline-block;
|
||||||
|
text-decoration: none;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 23px;
|
||||||
|
height: 24px;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0 10px 1px;
|
||||||
|
cursor: pointer;
|
||||||
|
border-width: 1px;
|
||||||
|
border-style: solid;
|
||||||
|
-webkit-border-radius: 3px;
|
||||||
|
-webkit-appearance: none;
|
||||||
|
border-radius: 3px;
|
||||||
|
white-space: nowrap;
|
||||||
|
-webkit-box-sizing: border-box;
|
||||||
|
-moz-box-sizing: border-box;
|
||||||
|
box-sizing: border-box;
|
||||||
|
background: #f3f3f3;
|
||||||
|
background-image: -webkit-gradient(linear, left top, left bottom, from(#fefefe), to(#f4f4f4));
|
||||||
|
background-image: -webkit-linear-gradient(top, #fefefe, #f4f4f4);
|
||||||
|
background-image: -moz-linear-gradient(top, #fefefe, #f4f4f4);
|
||||||
|
background-image: -o-linear-gradient(top, #fefefe, #f4f4f4);
|
||||||
|
background-image: linear-gradient(to bottom, #fefefe, #f4f4f4);
|
||||||
|
border-color: #bbb;
|
||||||
|
color: #900;
|
||||||
|
text-shadow: 0 1px 0 #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-warning:hover,
|
||||||
|
.button-warning:focus {
|
||||||
|
background: #f3f3f3;
|
||||||
|
background-image: -webkit-gradient(linear, left top, left bottom, from(#fff), to(#f3f3f3));
|
||||||
|
background-image: -webkit-linear-gradient(top, #fff, #f3f3f3);
|
||||||
|
background-image: -moz-linear-gradient(top, #fff, #f3f3f3);
|
||||||
|
background-image: -ms-linear-gradient(top, #fff, #f3f3f3);
|
||||||
|
background-image: -o-linear-gradient(top, #fff, #f3f3f3);
|
||||||
|
background-image: linear-gradient(to bottom, #fff, #f3f3f3);
|
||||||
|
border-color: #900;
|
||||||
|
color: #a00;
|
||||||
|
-webkit-box-shadow: 1px 1px 1px rgba(0,0,0,.2);
|
||||||
|
box-shadow: 1px 1px 1px rgba(0,0,0,.2);
|
||||||
|
}
|
||||||
|
|
||||||
|
.button-warning:active {
|
||||||
|
background: #eee;
|
||||||
|
background-image: -webkit-gradient(linear, left top, left bottom, from(#f4f4f4), to(#fefefe));
|
||||||
|
background-image: -webkit-linear-gradient(top, #f4f4f4, #fefefe);
|
||||||
|
background-image: -moz-linear-gradient(top, #f4f4f4, #fefefe);
|
||||||
|
background-image: -ms-linear-gradient(top, #f4f4f4, #fefefe);
|
||||||
|
background-image: -o-linear-gradient(top, #f4f4f4, #fefefe);
|
||||||
|
background-image: linear-gradient(to bottom, #f4f4f4, #fefefe);
|
||||||
|
border-color: #900;
|
||||||
|
color: #a00;
|
||||||
|
text-shadow: 0 -1px 0 #fff;
|
||||||
|
-webkit-box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 );
|
||||||
|
box-shadow: inset 0 2px 5px -3px rgba( 0, 0, 0, 0.5 );
|
||||||
|
}
|
||||||
|
|
|
@ -224,6 +224,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) {
|
||||||
<script>
|
<script>
|
||||||
jQuery(document).ready(function($) {
|
jQuery(document).ready(function($) {
|
||||||
jQuery( "#<?php echo $this->plugin_constant ?>-settings" ).tabs();
|
jQuery( "#<?php echo $this->plugin_constant ?>-settings" ).tabs();
|
||||||
|
jQuery( "#<?php echo $this->plugin_constant ?>-commands" ).tabs();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -266,13 +267,6 @@ if ( ! class_exists( 'WP_FFPC' ) ) {
|
||||||
<div class='updated settings-error'><p><strong><?php _e( 'Precache process was started, it is now running in the background, please be patient, it may take a very long time to finish.' , $this->plugin_constant ) ?></strong></p></div>
|
<div class='updated settings-error'><p><strong><?php _e( 'Precache process was started, it is now running in the background, please be patient, it may take a very long time to finish.' , $this->plugin_constant ) ?></strong></p></div>
|
||||||
<?php endif;
|
<?php endif;
|
||||||
|
|
||||||
/**
|
|
||||||
* if options were saved, display saved message
|
|
||||||
*/
|
|
||||||
if ( $_GET[ self::key_precache_disabled ]=='true' || $this->status == 5 || $this->shell_function == false ) : ?>
|
|
||||||
<div class='error'><p><strong><?php _e( "Precache functionality is disabled due to unavailable system call function. <br />Since precaching may take a very long time, it's done through a background CLI process in order not to run out of max execution time of PHP. Please enable one of the following functions if you whish to use precaching: " , $this->plugin_constant ) ?><?php echo join( ',' , $this->shell_possibilities ); ?></strong></p></div>
|
|
||||||
<?php endif;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* the admin panel itself
|
* the admin panel itself
|
||||||
*/
|
*/
|
||||||
|
@ -571,15 +565,56 @@ if ( ! class_exists( 'WP_FFPC' ) ) {
|
||||||
|
|
||||||
<p class="clear">
|
<p class="clear">
|
||||||
<input class="button-primary" type="submit" name="<?php echo $this->button_save ?>" id="<?php echo $this->button_save ?>" value="<?php _e('Save Changes', $this->plugin_constant ) ?>" />
|
<input class="button-primary" type="submit" name="<?php echo $this->button_save ?>" id="<?php echo $this->button_save ?>" value="<?php _e('Save Changes', $this->plugin_constant ) ?>" />
|
||||||
<?php $disabled = ( $this->shell_function == false ) ? 'disabled="disabled"' : '' ; ?>
|
|
||||||
<input <?php echo $disabled ?> class="button-primary" type="submit" name="<?php echo $this->button_precache ?>" id="<?php echo $this->button_precache ?>" value="<?php _e('Pre-cache post-like entries', $this->plugin_constant ) ?>" />
|
|
||||||
|
|
||||||
<input class="button-secondary error" style="float: right" type="submit" name="<?php echo $this->button_flush ?>" id="<?php echo $this->button_flush ?>" value="<?php _e('Clear cache', $this->plugin_constant ) ?>" />
|
|
||||||
<input class="button-secondary error" style="float: right" type="submit" name="<?php echo $this->button_delete ?>" id="<?php echo $this->button_delete ?>" value="<?php _e('Delete options from DB', $this->plugin_constant ) ?>" />
|
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<form method="post" action="#" id="<?php echo $this->plugin_constant ?>-commands" class="plugin-admin" style="padding-top:2em;">
|
||||||
|
|
||||||
|
<ul class="tabs">
|
||||||
|
<li><a href="#<?php echo $this->plugin_constant ?>-precache" class="wp-switch-editor"><?php _e( 'Precache', $this->plugin_constant ); ?></a></li>
|
||||||
|
<li><a href="#<?php echo $this->plugin_constant ?>-flush" class="wp-switch-editor"><?php _e( 'Empty cache', $this->plugin_constant ); ?></a></li>
|
||||||
|
<li><a href="#<?php echo $this->plugin_constant ?>-reset" class="wp-switch-editor"><?php _e( 'Reset settings', $this->plugin_constant ); ?></a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<fieldset id="<?php echo $this->plugin_constant ?>-precache">
|
||||||
|
<legend><?php _e( 'Precache', $this->plugin_constant ); ?></legend>
|
||||||
|
<dl>
|
||||||
|
<dt>
|
||||||
|
<?php if ( $_GET[ self::key_precache_disabled ]=='true' || $this->status == 5 || $this->shell_function == false ) : ?>
|
||||||
|
<strong><?php _e( "Precache functionality is disabled due to unavailable system call function. <br />Since precaching may take a very long time, it's done through a background CLI process in order not to run out of max execution time of PHP. Please enable one of the following functions if you whish to use precaching: " , $this->plugin_constant ) ?><?php echo join( ',' , $this->shell_possibilities ); ?></strong>
|
||||||
|
<?php else: ?>
|
||||||
|
<input class="button-secondary" type="submit" name="<?php echo $this->button_precache ?>" id="<?php echo $this->button_precache ?>" value="<?php _e('Pre-cache', $this->plugin_constant ) ?>" />
|
||||||
|
<?php endif; ?>
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
<span class="description"><?php _e('Start a background process that visits all permalinks of all blogs it can found thus forces WordPress to generate cached version of all the pages.', $this->plugin_constant); ?></span>
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
</fieldset>
|
||||||
|
<fieldset id="<?php echo $this->plugin_constant ?>-flush">
|
||||||
|
<legend><?php _e( 'Precache', $this->plugin_constant ); ?></legend>
|
||||||
|
<dl>
|
||||||
|
<dt>
|
||||||
|
<input class="button-warning" type="submit" name="<?php echo $this->button_flush ?>" id="<?php echo $this->button_flush ?>" value="<?php _e('Clear cache', $this->plugin_constant ) ?>" />
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
<span class="description"><?php _e ( "Clear all entries in the storage, including the ones that were set by other processes.", $this->plugin_constant ); ?> </span>
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
</fieldset>
|
||||||
|
<fieldset id="<?php echo $this->plugin_constant ?>-reset">
|
||||||
|
<legend><?php _e( 'Precache', $this->plugin_constant ); ?></legend>
|
||||||
|
<dl>
|
||||||
|
<dt>
|
||||||
|
<input class="button-warning" type="submit" name="<?php echo $this->button_delete ?>" id="<?php echo $this->button_delete ?>" value="<?php _e('Reset options', $this->plugin_constant ) ?>" />
|
||||||
|
</dt>
|
||||||
|
<dd>
|
||||||
|
<span class="description"><?php _e ( "Reset settings to defaults.", $this->plugin_constant ); ?> </span>
|
||||||
|
</dd>
|
||||||
|
</dl>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
@ -772,27 +807,37 @@ if ( ! class_exists( 'WP_FFPC' ) ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generate cache entry for every available permalink, might be very-very slow
|
* generate cache entry for every available permalink, might be very-very slow,
|
||||||
|
* therefore it starts a background process
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function precache () {
|
private function precache () {
|
||||||
/* container for links to precache */
|
/* container for links to precache, well be accessed by reference */
|
||||||
$links = array();
|
$links = array();
|
||||||
|
|
||||||
|
/* when plugin is network wide active, we need to pre-cache for all link of all blogs */
|
||||||
if ( $this->network ) {
|
if ( $this->network ) {
|
||||||
|
/* list all blogs */
|
||||||
$blog_list = get_blog_list( 0, 'all' );
|
$blog_list = get_blog_list( 0, 'all' );
|
||||||
foreach ($blog_list as $blog) {
|
foreach ($blog_list as $blog) {
|
||||||
|
/* get permalinks for this blog */
|
||||||
$this->precache_list_permalinks ( $links, $blog['blog_id'] );
|
$this->precache_list_permalinks ( $links, $blog['blog_id'] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
/* no network, better */
|
||||||
$this->precache_list_permalinks ( $links, false );
|
$this->precache_list_permalinks ( $links, false );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* temporary php file, will destroy itself after finish in order to clean up */
|
||||||
$tmpfile = tempnam(sys_get_temp_dir(), 'wp-ffpc');
|
$tmpfile = tempnam(sys_get_temp_dir(), 'wp-ffpc');
|
||||||
|
|
||||||
|
/* double check if we do have any links to pre-cache */
|
||||||
if ( !empty ( $links ) ) :
|
if ( !empty ( $links ) ) :
|
||||||
|
|
||||||
|
/* this is the precacher php worker file: logs the links, their generation time and the generated content size
|
||||||
|
* writes the logfile and destroys itself afterwards
|
||||||
|
*/
|
||||||
$out .= '<?php
|
$out .= '<?php
|
||||||
$links = ' . var_export ( $links , true ) . ';
|
$links = ' . var_export ( $links , true ) . ';
|
||||||
|
|
||||||
|
@ -815,6 +860,7 @@ if ( ! class_exists( 'WP_FFPC' ) ) {
|
||||||
?>';
|
?>';
|
||||||
|
|
||||||
file_put_contents ( $tmpfile, $out );
|
file_put_contents ( $tmpfile, $out );
|
||||||
|
/* call the precache worker file in the background */
|
||||||
$shellfunction = $this->shell_function;
|
$shellfunction = $this->shell_function;
|
||||||
$shellfunction( 'php '. $tmpfile .' >'. $this->precache_logfile .' 2>&1 &' );
|
$shellfunction( 'php '. $tmpfile .' >'. $this->precache_logfile .' 2>&1 &' );
|
||||||
|
|
||||||
|
@ -827,25 +873,29 @@ if ( ! class_exists( 'WP_FFPC' ) ) {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private function precache_list_permalinks ( &$links, $site = false ) {
|
private function precache_list_permalinks ( &$links, $site = false ) {
|
||||||
|
/* $post will be populated when running throught the posts */
|
||||||
global $post;
|
global $post;
|
||||||
include_once ( ABSPATH . "wp-load.php" );
|
include_once ( ABSPATH . "wp-load.php" );
|
||||||
|
|
||||||
|
/* if a site id was provided, save current blog and change to the other site */
|
||||||
if ( $site !== false ) {
|
if ( $site !== false ) {
|
||||||
$current_blog = get_current_blog_id();
|
$current_blog = get_current_blog_id();
|
||||||
switch_to_blog( $site );
|
switch_to_blog( $site );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* get all published posts */
|
||||||
$args = array (
|
$args = array (
|
||||||
'post_type' => 'any',
|
'post_type' => 'any',
|
||||||
'posts_per_page' => -1,
|
'posts_per_page' => -1,
|
||||||
'post_status' => 'publish',
|
'post_status' => 'publish',
|
||||||
);
|
);
|
||||||
|
|
||||||
$posts = new WP_Query( $args );
|
$posts = new WP_Query( $args );
|
||||||
|
|
||||||
|
/* get all the posts, one by one */
|
||||||
while ( $posts->have_posts() ) {
|
while ( $posts->have_posts() ) {
|
||||||
$posts->the_post();
|
$posts->the_post();
|
||||||
|
|
||||||
|
/* get the permalink for currently selected post */
|
||||||
switch ($post->post_type) {
|
switch ($post->post_type) {
|
||||||
case 'revision':
|
case 'revision':
|
||||||
case 'nav_menu_item':
|
case 'nav_menu_item':
|
||||||
|
@ -864,12 +914,15 @@ if ( ! class_exists( 'WP_FFPC' ) ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* collect permalinks */
|
||||||
$links[] = $permalink;
|
$links[] = $permalink;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* just in case, reset $post */
|
||||||
wp_reset_postdata();
|
wp_reset_postdata();
|
||||||
|
|
||||||
|
/* switch back to original site if we navigated away */
|
||||||
if ( $site !== false ) {
|
if ( $site !== false ) {
|
||||||
switch_to_blog( $current_blog );
|
switch_to_blog( $current_blog );
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue