note 88785 deleted from function.flock by danbrown
| From: | danbrown@php.net | Date: | Sat, 07 Feb 2009 18:17:37 +0000 |
| Subject: | note 88785 deleted from function.flock by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-150367@lists.php.net to get a copy of this message | ||
Note Submitter: dave at wp dot pl
----
I have made below script and I was suprised because it does NOT work!
<?PHP
$content = "";
$input = fopen ("lock_test.txt", "w");
if (flock ($input, 6) == true){
echo "in...<br/>";
$time=time();
while (time()<$time+5)
{
}
echo "out...<br/>";
flock ($input, 3);
}
else echo "can't acquire block...";
fclose ($input);
//sleep () was used to give myself enough time to switch to another browser window,
//invoke the script again to guarantee parallelism and make the notepad test to see
//if an error occurred with other proccess
?>
This script is similar to Daniel Gandra's script, witch works well:
<?PHP
$content = "";
$input = fopen ("lock_test.txt", "w");
if (flock ($input, 6) == true){
echo "in...<br/>";
sleep (5);
echo "out...<br/>";
flock ($input, 3);
}
else echo "can't acquire block...";
fclose ($input);
//sleep () was used to give myself enough time to switch to another browser window,
//invoke the script again to guarantee parallelism and make the notepad test to see
//if an error occurred with other proccess
?>
One difference
using:
$time=time();
while (time()<$time+5)
{
}
instead:
sleep (5);