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