note 101701 modified in function.flock by danbrown

From: Date: Thu, 06 Jan 2011 01:20:10 +0000
Subject: note 101701 modified in function.flock by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-175476@lists.php.net to get a copy of this message
LOCK_NB seems to be checked and works fine in Windows, too, in PHP 5.3.3. For instance, try concurrently running two instances of the following script (via the CLI). The second prints "Didn't quite get the lock..." as expected, whereas w/o the LOCK_NB flag, it just hangs. <?php $x = fopen("flocktest.txt", "w"); if (flock($x, LOCK_EX|LOCK_NB)) { print "No problems, I got the lock, now I'm going to sit on it."; while (true) sleep(5); } else { print "Didn't quite get the lock. Quitting now. Good night."; } fclose($x); ?> --was-- LOCK_NB seems to be checked and works fine in Windows, too, in PHP 5.3.3. For instance, try concurrently running two instances of the following script (via the CLI). The second prints "Didn't quite get the lock..." as expected, whereas w/o the LOCK_NB flag, it just hangs. <?php $x = fopen("flocktest.txt", "w"); if (flock($x, LOCK_EX|LOCK_NB)) { print "No problems, I got the lock, now I'm going to sit on it."; while (true) sleep(5); } else { print "Didn't quite get the lock. Quitting now. Good night."; } fclose($x); http://php.net/manual/en/function.flock.php

« previous php.notes (#175476) next »