xref: /PHP-7.3/ext/standard/tests/file/flock.phpt (revision 782352c5)
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
36echo "Done\n";
37?>
38--CLEAN--
39<?php
40$file = dirname(__FILE__)."/flock.dat";
41unlink($file);
42?>
43--EXPECTF--
44Warning: flock() expects at least 2 parameters, 0 given in %s on line %d
45NULL
46
47Warning: flock() expects parameter 1 to be resource, string given in %s on line %d
48NULL
49
50Warning: flock(): supplied resource is not a valid stream resource in %s on line %d
51bool(false)
52bool(true)
53bool(true)
54bool(true)
55bool(true)
56bool(true)
57int(0)
58bool(true)
59int(0)
60bool(true)
61int(0)
62bool(true)
63int(0)
64bool(true)
65
66Warning: flock(): Illegal operation argument in %s on line %d
67bool(false)
68Done
69