“Process locking” folosind PHP / *nix

< ?php
$fh = fopen(dirname(__FILE__).DIRECTORY_SEPARATOR.'.lock', 'w+');
 
if (flock($fh, LOCK_EX | LOCK_NB) === TRUE)
{
	// Functional code
	$exit = FALSE;
	while($exit === FALSE)
	{
		$exit = TRUE;
		sleep(10);
	}
	// End Functional code
	flock($fh, LOCK_UN);
}
else
{
	echo "This script is locked by another process.\n";
}
 
fclose($fh);