I have an index.php script that I use as a post-commit URL on a Google Code site. This script clones a directory and builds a project that may take some work.
index.php
You can use flock with LOCK_EX to gain an exclusive lock on a file.
LOCK_EX
E.g.:
For PHP versions after 5.3.2 you need to manually release the lock using flock($fp, LOCK_UN);