Skip to content

Instantly share code, notes, and snippets.

@tollmanz
Created April 10, 2012 15:50
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/2352340 to your computer and use it in GitHub Desktop.
Save tollmanz/2352340 to your computer and use it in GitHub Desktop.
Another locking technique that should only allow one execution per hour
<?php
function test_race() {
$key = date( 'YdmH', time() );
wp_cache_add( $key, 0 );
if ( 1 !== wp_cache_incr( $key ) )
return false;
// Do the things
}
add_action( 'init', 'test_race' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment