Skip to content

Instantly share code, notes, and snippets.

@tollmanz
Created April 10, 2012 05:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tollmanz/2348484 to your computer and use it in GitHub Desktop.
Save tollmanz/2348484 to your computer and use it in GitHub Desktop.
A locking technique for high concurrency situations in WordPress
<?php
function test_race() {
if ( wp_cache_get( 'lock' ) )
return false;
wp_cache_add( 'lock', 1 );
$key = time();
wp_cache_add( $key, 0 );
if ( 1 !== wp_cache_incr( $key ) )
return false;
// do the things
wp_cache_delete( 'lock' );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment