Skip to content

Commit

Permalink
Merge pull request #174 from Automattic/semaphore_cleanup
Browse files Browse the repository at this point in the history
Make it harder to use file locking because it's not really needed.
Remove IPC_CREAT constant because it doesn't seem to be defined any more.
Updated the readme.txt too with docs on disabling file locking.
  • Loading branch information
donnchawp committed Feb 1, 2017
2 parents ae470f3 + fef25a8 commit ddc92f5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 4 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ Removed malware URL in a code comment.
* Fixed bug when by not running sem_remove after sem_release. See https://github.com/Automattic/wp-super-cache/issues/85
* Fixed a PHP error impacting PHP 7.1.
* Fixed a bug where we cached PUT and DELETE requests. We're treating them like POST requests now.
* Updated the settings page, moving things around. [#173](https://github.com/Automattic/wp-super-cache/pull/173)
* Make file locking less attractive on the settings page and fixed the WPSC_DISABLE_LOCKING constant so it really disables file locking even if the user has enabled it already.
* Added a WPSC_REMOVE_SEMAPHORE constant that must be defined if sem_remove() is to be used as it may cause problems. [#174](https://github.com/Automattic/wp-super-cache/pull/174)

= 1.4.8 =
* Removed malware URL in a code comment. (harmless to operation of plugin but gets flagged by A/V software)
Expand Down Expand Up @@ -564,6 +567,7 @@ If that doesn't work, add this line to your wp-config.php:
`AddDefaultCharset CHARSET`
27. Use [Cron View](http://wordpress.org/plugins/cron-view/) to help diagnose garbage collection and preload problems. Use the plugin to make sure jobs are scheduled and for what time. Look for the wp_cache_gc and wp_cache_full_preload_hook jobs.
18. The error message, "WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory." appears at the end of every page. You can delete wp-content/advanced-cache.php and reload the plugin settings page or edit wp-config.php and look for WPCACHEHOME and make sure it points at the wp-super-cache folder. This will normally be wp-content/plugins/wp-super-cache/ but you'll likely need the full path to that file (so it's easier to let the settings page fix it). If it is not correct the caching engine will not load.
19. If your server is running into trouble because of the number of semaphores used by the plugin it's because your users are using file locking which is not recommended (but is needed by a small number of users). You can globally disable file locking by defining the constant WPSC_DISABLE_LOCKING, or defining the constant WPSC_REMOVE_SEMAPHORE so that sem_remove() is called after every page is cached but that seems to cause problems for other processes requesting the same semaphore. Best to disable it.


== CDN ==
Expand Down
15 changes: 8 additions & 7 deletions wp-cache-phase2.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function wp_cache_is_rejected($uri) {
function wp_cache_mutex_init() {
global $mutex, $wp_cache_mutex_disabled, $use_flock, $blog_cache_dir, $mutex_filename, $sem_id;

if( isset( $wp_cache_mutex_disabled) && $wp_cache_mutex_disabled )
if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) )
return true;

if( !is_bool( $use_flock ) ) {
Expand All @@ -175,14 +175,14 @@ function wp_cache_mutex_init() {
$mutex = @fopen( $blog_cache_dir . $mutex_filename, 'w' );
} else {
wp_cache_debug( "Created mutex lock on semaphore: {$sem_id}", 5 );
$mutex = @sem_get( $sem_id, 1, 0644 | IPC_CREAT, 1 );
$mutex = @sem_get( $sem_id, 1, 0666, 1 );
}
}

function wp_cache_writers_entry() {
global $mutex, $wp_cache_mutex_disabled, $use_flock;

if( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled )
if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) )
return true;

if( !$mutex ) {
Expand All @@ -195,7 +195,7 @@ function wp_cache_writers_entry() {
flock($mutex, LOCK_EX);
} else {
wp_cache_debug( "grabbing lock using sem_acquire()", 5 );
sem_acquire($mutex);
@sem_acquire($mutex);
}

return true;
Expand All @@ -204,7 +204,7 @@ function wp_cache_writers_entry() {
function wp_cache_writers_exit() {
global $mutex, $wp_cache_mutex_disabled, $use_flock;

if( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled )
if ( defined( 'WPSC_DISABLE_LOCKING' ) || ( isset( $wp_cache_mutex_disabled ) && $wp_cache_mutex_disabled ) )
return true;

if( !$mutex ) {
Expand All @@ -217,8 +217,9 @@ function wp_cache_writers_exit() {
flock( $mutex, LOCK_UN );
} else {
wp_cache_debug( "releasing lock using sem_release() and sem_remove()", 5 );
sem_release( $mutex );
sem_remove( $mutex );
@sem_release( $mutex );
if ( defined( "WPSC_REMOVE_SEMAPHORE" ) )
@sem_remove( $mutex );
}
}

Expand Down
2 changes: 1 addition & 1 deletion wp-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ function toggleLayer( whichLayer ) {
<label><input type='checkbox' name='wp_cache_refresh_single_only' <?php if( $wp_cache_refresh_single_only ) echo "checked"; ?> value='1'> <?php _e( 'Only refresh current page when comments made.', 'wp-super-cache' ); ?></label><br />
<label><input type='checkbox' name='wp_supercache_cache_list' <?php if( $wp_supercache_cache_list ) echo "checked"; ?> value='1'> <?php _e( 'List the newest cached pages on this page.', 'wp-super-cache' ); ?></label><br />
<?php if( false == defined( 'WPSC_DISABLE_LOCKING' ) ) { ?>
<label><input type='checkbox' name='wp_cache_mutex_disabled' <?php if( !$wp_cache_mutex_disabled ) echo "checked"; ?> value='0'> <?php _e( 'Coarse file locking. You probably don&#8217;t need this but it may help if your server is underpowered. Warning! <em>May cause your server to lock up in very rare cases!</em>', 'wp-super-cache' ); ?></label><br />
<label><input type='checkbox' name='wp_cache_mutex_disabled' <?php if( !$wp_cache_mutex_disabled ) echo "checked"; ?> value='0'> <?php _e( 'Coarse file locking. You do not need this as it will slow down your website.', 'wp-super-cache' ); ?></label><br />
<?php } ?>
<label><input type='checkbox' name='wp_super_cache_late_init' <?php if( $wp_super_cache_late_init ) echo "checked"; ?> value='1'> <?php _e( 'Late init. Display cached files after WordPress has loaded. Most useful in legacy mode.', 'wp-super-cache' ); ?></label><br />
<?php if ( $_wp_using_ext_object_cache ) {
Expand Down

0 comments on commit ddc92f5

Please sign in to comment.