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$file_path = dirname(__FILE__);
13
14$file_handle = fopen("$file_path/lock.tmp", "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("$file_path/lock.tmp");
21
22mkdir("$file_path/dir");
23$dir_handle = opendir("$file_path/dir");
24var_dump(flock($dir_handle, LOCK_SH|LOCK_NB));
25var_dump(flock($dir_handle, LOCK_UN));
26var_dump(flock($dir_handle, LOCK_EX));
27var_dump(flock($dir_handle, LOCK_UN));
28closedir($dir_handle);
29rmdir("$file_path/dir");
30
31echo "\n*** Done ***\n";
32?>
33--EXPECTF--
34*** Testing flock() fun with file and dir ***
35bool(true)
36bool(true)
37bool(true)
38bool(true)
39bool(false)
40bool(false)
41bool(false)
42bool(false)
43
44*** Done ***
45