xref: /PHP-5.5/ext/standard/tests/file/flock.phpt (revision 29a9ba96)
1--TEST--
2flock() tests
3--FILE--
4<?php
5
6$file = dirname(__FILE__)."/flock.dat";
7
8var_dump(flock());
9var_dump(flock("", "", $var));
10
11$fp = fopen($file, "w");
12fclose($fp);
13
14var_dump(flock($fp, LOCK_SH|LOCK_NB));
15
16$fp = fopen($file, "w");
17
18var_dump(flock($fp, LOCK_SH|LOCK_NB));
19var_dump(flock($fp, LOCK_UN));
20var_dump(flock($fp, LOCK_EX));
21var_dump(flock($fp, LOCK_UN));
22
23$would = array(1,2,3);
24var_dump(flock($fp, LOCK_SH|LOCK_NB, $would));
25var_dump($would);
26var_dump(flock($fp, LOCK_UN, $would));
27var_dump($would);
28var_dump(flock($fp, LOCK_EX, $would));
29var_dump($would);
30var_dump(flock($fp, LOCK_UN, $would));
31var_dump($would);
32
33var_dump(flock($fp, -1));
34var_dump(flock($fp, 0));
35
36@unlink($file);
37echo "Done\n";
38?>
39--EXPECTF--
40Warning: flock() expects at least 2 parameters, 0 given in %s on line %d
41NULL
42
43Warning: flock() expects parameter 1 to be resource, string given in %s on line %d
44NULL
45
46Warning: flock(): %d is not a valid stream resource in %s on line %d
47bool(false)
48bool(true)
49bool(true)
50bool(true)
51bool(true)
52bool(true)
53int(0)
54bool(true)
55int(0)
56bool(true)
57int(0)
58bool(true)
59int(0)
60bool(true)
61
62Warning: flock(): Illegal operation argument in %s on line %d
63bool(false)
64Done
65