1--TEST--
2Test flock() function: Basic functionality
3--FILE--
4<?php
5/*
6Prototype: bool flock(resource $handle, int $operation [, int &$wouldblock]);
7Description: PHP supports a portable way of locking complete files
8  in an advisory way
9*/
10
11echo "*** Testing flock() fun with file and dir ***\n";
12
13$lock_file = preg_replace("~\.phpt?$~", null, __FILE__);
14
15$file_handle = fopen($lock_file, "w");
16var_dump(flock($file_handle, LOCK_SH|LOCK_NB));
17var_dump(flock($file_handle, LOCK_UN));
18var_dump(flock($file_handle, LOCK_EX));
19var_dump(flock($file_handle, LOCK_UN));
20fclose($file_handle);
21unlink($lock_file);
22
23$lock_dir = sprintf("%s.dir", preg_replace("~\.phpt?$~", null, __FILE__));
24
25mkdir($lock_dir);
26$dir_handle = opendir($lock_dir);
27var_dump(flock($dir_handle, LOCK_SH|LOCK_NB));
28var_dump(flock($dir_handle, LOCK_UN));
29var_dump(flock($dir_handle, LOCK_EX));
30var_dump(flock($dir_handle, LOCK_UN));
31closedir($dir_handle);
32rmdir($lock_dir);
33
34echo "\n*** Done ***\n";
35?>
36--EXPECT--
37*** Testing flock() fun with file and dir ***
38bool(true)
39bool(true)
40bool(true)
41bool(true)
42bool(false)
43bool(false)
44bool(false)
45bool(false)
46
47*** Done ***
48