资 源 简 介
This project provides a SIMPLE standa-lone multi-platform way to extablish mutex locks in php scripts.
I needed this to ensure that a scheduled cron job wouldn"t run UNTIL another script was finished.
It works by putting a lock on a temp file that is named according to the lock name but with all the non alphanumeric characters stripped out.
It is VERY easy to use.
$mutex = new Mutex("attendeeEmail");while(!$mutex->getLock()){ sleep(.5);}//Do tasks that should never be run more than one at a time.$mutex->releaseLock();
There is also a "isLocked" method. I just write my scripts to not run if it can"t get a lock. PHP will release the lock when the request is done if you didn"t manually release it. Releasing the lock also closes the open filehandle. Currently it uses the php temporary file functions to find the temp directory. You can easily change this to manually set a writable directory.