Skip to content

Instantly share code, notes, and snippets.

@ryo88c
Created March 30, 2012 01:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryo88c/2245731 to your computer and use it in GitHub Desktop.
Save ryo88c/2245731 to your computer and use it in GitHub Desktop.
[BEAR] 排他ロックする around アドバイス
<?php
class App_Aspect_Lock implements BEAR_Aspect_Around_Interface{
public function around(array $values, BEAR_Aspect_JoinPoint $joinPoint){
$lock = sprintf('%s/tmp/locks/%s', _BEAR_APP_HOME, sha1(serialize($joinPoint->getMethodReflection())));
if(!file_exists($lock)){
touch($lock);
}
if(file_get_contents($lock)){
return false;
}
file_put_contents($lock, 1);
$joinPoint->proceed($values);
file_put_contents($lock, null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment