summaryrefslogtreecommitdiff
path: root/ext/standard/tests/file/flock_variation1.phpt
diff options
context:
space:
mode:
Diffstat (limited to 'ext/standard/tests/file/flock_variation1.phpt')
-rw-r--r--ext/standard/tests/file/flock_variation1.phpt62
1 files changed, 62 insertions, 0 deletions
diff --git a/ext/standard/tests/file/flock_variation1.phpt b/ext/standard/tests/file/flock_variation1.phpt
new file mode 100644
index 0000000000..3e3f5108e8
--- /dev/null
+++ b/ext/standard/tests/file/flock_variation1.phpt
@@ -0,0 +1,62 @@
+--TEST--
+Test flock() function: usage variations
+--CREDITS--
+Dave Kelsey <d_kelsey@uk.ibm.com>
+--SKIPIF--
+<?php
+if (substr(PHP_OS, 0, 3) == 'WIN') {
+ die('skip.. not for Windows');
+}
+if (function_exists("pcntl_fork") == FALSE) {
+ die('skip.. no pcntl_fork()');
+}
+?>
+--FILE--
+<?php
+/*
+Prototype: bool flock(resource $handle, int $operation [, int &$wouldblock]);
+Description: PHP supports a portable way of locking complete files in an advisory way
+*/
+
+echo "*** Test flock() function: with the operations given as numeric values ***\n";
+
+$filename = dirname(__FILE__)."/flock_variation1.tmp";
+$file_handle = fopen($filename, "w");
+fwrite($file_handle, str_repeat("Hello2World", 10) );
+fclose($file_handle);
+
+$file_read = fopen($filename, "r");
+
+$pid = pcntl_fork();
+echo "-- child process is created --\n";
+if ($pid == -1) {
+ die('could not fork');
+} else if ($pid) {
+ echo "-- Trying to get the Reader Lock --\n";
+ if( flock($file_read, LOCK_EX) ) {
+ echo "-- Got Lock --\n";
+ sleep(5);
+ flock($file_read, LOCK_UN);
+ }
+ else
+ echo "-- Couldn't get the Lock --\n";
+} else {
+ echo "-- Trying to get the Writer Lock --\n";
+ if( flock($file_read, LOCK_EX) ) {
+ echo "-- Got Lock --\n";
+ flock($file_read, LOCK_UN);
+ }
+ else
+ echo "-- Couldn't get the Lock --\n";
+
+}
+
+echo "*** Done ***\n";
+?>
+--CLEAN--
+<?php
+fclose($file_read);
+fclose($file_write);
+unlink($filename);
+?>
+--EXPECTF--