xref: /PHP-8.0/ext/standard/tests/file/flock.phpt (revision e950ca13)
1--TEST--
2flock() tests
3--FILE--
4<?php
5
6$file = __DIR__."/flock.dat";
7
8$fp = fopen($file, "w");
9fclose($fp);
10
11try {
12    var_dump(flock($fp, LOCK_SH|LOCK_NB));
13} catch (TypeError $e) {
14    echo $e->getMessage(), "\n";
15}
16
17$fp = fopen($file, "w");
18
19var_dump(flock($fp, LOCK_SH|LOCK_NB));
20var_dump(flock($fp, LOCK_UN));
21var_dump(flock($fp, LOCK_EX));
22var_dump(flock($fp, LOCK_UN));
23
24$would = array(1,2,3);
25var_dump(flock($fp, LOCK_SH|LOCK_NB, $would));
26var_dump($would);
27var_dump(flock($fp, LOCK_UN, $would));
28var_dump($would);
29var_dump(flock($fp, LOCK_EX, $would));
30var_dump($would);
31var_dump(flock($fp, LOCK_UN, $would));
32var_dump($would);
33
34var_dump(flock($fp, -1));
35
36try {
37    var_dump(flock($fp, 0));
38} catch (\ValueError $e) {
39    echo $e->getMessage() . \PHP_EOL;
40}
41
42?>
43--CLEAN--
44<?php
45$file = __DIR__."/flock.dat";
46unlink($file);
47?>
48--EXPECT--
49flock(): supplied resource is not a valid stream resource
50bool(true)
51bool(true)
52bool(true)
53bool(true)
54bool(true)
55int(0)
56bool(true)
57int(0)
58bool(true)
59int(0)
60bool(true)
61int(0)
62bool(true)
63flock(): Argument #2 ($operation) must be one of LOCK_SH, LOCK_EX, or LOCK_UN
64