Created
April 10, 2012 05:26
-
-
Save tollmanz/2348484 to your computer and use it in GitHub Desktop.
A locking technique for high concurrency situations in WordPress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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