1--TEST--
2Test flock() function: Variations
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 the various operation and
12            wouldblock values                                ***\n";
13$file = dirname(__FILE__)."/flock.tmp";
14$fp = fopen($file, "w");
15
16/* array of operatons */
17$operations = array(
18  LOCK_SH,
19  LOCK_EX,
20  LOCK_SH|LOCK_NB,
21  LOCK_EX|LOCK_NB,
22  LOCK_SH|LOCK_EX,
23  LOCK_UN,
24  1,
25  2,
26  2.234,
27  TRUE
28);
29
30/* array of wouldblocks */
31$wouldblocks = array(
32  0,
33  1,
34  2,
35  1.234,
36  TRUE,
37  FALSE,
38  NULL,
39  array(1,2,3),
40  array(),
41  "string",
42  "",
43  /* binary input */
44  b"string",
45  b"",
46  "\0"
47);
48
49$i = 0;
50foreach($operations as $operation) {
51  echo "--- Outer iteration $i ---\n";
52  var_dump(flock($fp, $operation));
53  $j = 0;
54  foreach($wouldblocks as $wouldblock) {
55    echo "-- Inner iteration $j in $i --\n";
56    var_dump(flock($fp, $operation, $wouldblock));
57    $j++;
58  }
59  $i++;
60}
61
62fclose($fp);
63@unlink($file);
64
65echo "\n*** Done ***\n";
66?>
67--EXPECTF--
68*** Testing flock() fun with the various operation and
69            wouldblock values                                ***
70--- Outer iteration 0 ---
71bool(true)
72-- Inner iteration 0 in 0 --
73bool(true)
74-- Inner iteration 1 in 0 --
75bool(true)
76-- Inner iteration 2 in 0 --
77bool(true)
78-- Inner iteration 3 in 0 --
79bool(true)
80-- Inner iteration 4 in 0 --
81bool(true)
82-- Inner iteration 5 in 0 --
83bool(true)
84-- Inner iteration 6 in 0 --
85bool(true)
86-- Inner iteration 7 in 0 --
87bool(true)
88-- Inner iteration 8 in 0 --
89bool(true)
90-- Inner iteration 9 in 0 --
91bool(true)
92-- Inner iteration 10 in 0 --
93bool(true)
94-- Inner iteration 11 in 0 --
95bool(true)
96-- Inner iteration 12 in 0 --
97bool(true)
98-- Inner iteration 13 in 0 --
99bool(true)
100--- Outer iteration 1 ---
101bool(true)
102-- Inner iteration 0 in 1 --
103bool(true)
104-- Inner iteration 1 in 1 --
105bool(true)
106-- Inner iteration 2 in 1 --
107bool(true)
108-- Inner iteration 3 in 1 --
109bool(true)
110-- Inner iteration 4 in 1 --
111bool(true)
112-- Inner iteration 5 in 1 --
113bool(true)
114-- Inner iteration 6 in 1 --
115bool(true)
116-- Inner iteration 7 in 1 --
117bool(true)
118-- Inner iteration 8 in 1 --
119bool(true)
120-- Inner iteration 9 in 1 --
121bool(true)
122-- Inner iteration 10 in 1 --
123bool(true)
124-- Inner iteration 11 in 1 --
125bool(true)
126-- Inner iteration 12 in 1 --
127bool(true)
128-- Inner iteration 13 in 1 --
129bool(true)
130--- Outer iteration 2 ---
131bool(true)
132-- Inner iteration 0 in 2 --
133bool(true)
134-- Inner iteration 1 in 2 --
135bool(true)
136-- Inner iteration 2 in 2 --
137bool(true)
138-- Inner iteration 3 in 2 --
139bool(true)
140-- Inner iteration 4 in 2 --
141bool(true)
142-- Inner iteration 5 in 2 --
143bool(true)
144-- Inner iteration 6 in 2 --
145bool(true)
146-- Inner iteration 7 in 2 --
147bool(true)
148-- Inner iteration 8 in 2 --
149bool(true)
150-- Inner iteration 9 in 2 --
151bool(true)
152-- Inner iteration 10 in 2 --
153bool(true)
154-- Inner iteration 11 in 2 --
155bool(true)
156-- Inner iteration 12 in 2 --
157bool(true)
158-- Inner iteration 13 in 2 --
159bool(true)
160--- Outer iteration 3 ---
161bool(true)
162-- Inner iteration 0 in 3 --
163bool(true)
164-- Inner iteration 1 in 3 --
165bool(true)
166-- Inner iteration 2 in 3 --
167bool(true)
168-- Inner iteration 3 in 3 --
169bool(true)
170-- Inner iteration 4 in 3 --
171bool(true)
172-- Inner iteration 5 in 3 --
173bool(true)
174-- Inner iteration 6 in 3 --
175bool(true)
176-- Inner iteration 7 in 3 --
177bool(true)
178-- Inner iteration 8 in 3 --
179bool(true)
180-- Inner iteration 9 in 3 --
181bool(true)
182-- Inner iteration 10 in 3 --
183bool(true)
184-- Inner iteration 11 in 3 --
185bool(true)
186-- Inner iteration 12 in 3 --
187bool(true)
188-- Inner iteration 13 in 3 --
189bool(true)
190--- Outer iteration 4 ---
191bool(true)
192-- Inner iteration 0 in 4 --
193bool(true)
194-- Inner iteration 1 in 4 --
195bool(true)
196-- Inner iteration 2 in 4 --
197bool(true)
198-- Inner iteration 3 in 4 --
199bool(true)
200-- Inner iteration 4 in 4 --
201bool(true)
202-- Inner iteration 5 in 4 --
203bool(true)
204-- Inner iteration 6 in 4 --
205bool(true)
206-- Inner iteration 7 in 4 --
207bool(true)
208-- Inner iteration 8 in 4 --
209bool(true)
210-- Inner iteration 9 in 4 --
211bool(true)
212-- Inner iteration 10 in 4 --
213bool(true)
214-- Inner iteration 11 in 4 --
215bool(true)
216-- Inner iteration 12 in 4 --
217bool(true)
218-- Inner iteration 13 in 4 --
219bool(true)
220--- Outer iteration 5 ---
221bool(true)
222-- Inner iteration 0 in 5 --
223bool(true)
224-- Inner iteration 1 in 5 --
225bool(true)
226-- Inner iteration 2 in 5 --
227bool(true)
228-- Inner iteration 3 in 5 --
229bool(true)
230-- Inner iteration 4 in 5 --
231bool(true)
232-- Inner iteration 5 in 5 --
233bool(true)
234-- Inner iteration 6 in 5 --
235bool(true)
236-- Inner iteration 7 in 5 --
237bool(true)
238-- Inner iteration 8 in 5 --
239bool(true)
240-- Inner iteration 9 in 5 --
241bool(true)
242-- Inner iteration 10 in 5 --
243bool(true)
244-- Inner iteration 11 in 5 --
245bool(true)
246-- Inner iteration 12 in 5 --
247bool(true)
248-- Inner iteration 13 in 5 --
249bool(true)
250--- Outer iteration 6 ---
251bool(true)
252-- Inner iteration 0 in 6 --
253bool(true)
254-- Inner iteration 1 in 6 --
255bool(true)
256-- Inner iteration 2 in 6 --
257bool(true)
258-- Inner iteration 3 in 6 --
259bool(true)
260-- Inner iteration 4 in 6 --
261bool(true)
262-- Inner iteration 5 in 6 --
263bool(true)
264-- Inner iteration 6 in 6 --
265bool(true)
266-- Inner iteration 7 in 6 --
267bool(true)
268-- Inner iteration 8 in 6 --
269bool(true)
270-- Inner iteration 9 in 6 --
271bool(true)
272-- Inner iteration 10 in 6 --
273bool(true)
274-- Inner iteration 11 in 6 --
275bool(true)
276-- Inner iteration 12 in 6 --
277bool(true)
278-- Inner iteration 13 in 6 --
279bool(true)
280--- Outer iteration 7 ---
281bool(true)
282-- Inner iteration 0 in 7 --
283bool(true)
284-- Inner iteration 1 in 7 --
285bool(true)
286-- Inner iteration 2 in 7 --
287bool(true)
288-- Inner iteration 3 in 7 --
289bool(true)
290-- Inner iteration 4 in 7 --
291bool(true)
292-- Inner iteration 5 in 7 --
293bool(true)
294-- Inner iteration 6 in 7 --
295bool(true)
296-- Inner iteration 7 in 7 --
297bool(true)
298-- Inner iteration 8 in 7 --
299bool(true)
300-- Inner iteration 9 in 7 --
301bool(true)
302-- Inner iteration 10 in 7 --
303bool(true)
304-- Inner iteration 11 in 7 --
305bool(true)
306-- Inner iteration 12 in 7 --
307bool(true)
308-- Inner iteration 13 in 7 --
309bool(true)
310--- Outer iteration 8 ---
311bool(true)
312-- Inner iteration 0 in 8 --
313bool(true)
314-- Inner iteration 1 in 8 --
315bool(true)
316-- Inner iteration 2 in 8 --
317bool(true)
318-- Inner iteration 3 in 8 --
319bool(true)
320-- Inner iteration 4 in 8 --
321bool(true)
322-- Inner iteration 5 in 8 --
323bool(true)
324-- Inner iteration 6 in 8 --
325bool(true)
326-- Inner iteration 7 in 8 --
327bool(true)
328-- Inner iteration 8 in 8 --
329bool(true)
330-- Inner iteration 9 in 8 --
331bool(true)
332-- Inner iteration 10 in 8 --
333bool(true)
334-- Inner iteration 11 in 8 --
335bool(true)
336-- Inner iteration 12 in 8 --
337bool(true)
338-- Inner iteration 13 in 8 --
339bool(true)
340--- Outer iteration 9 ---
341bool(true)
342-- Inner iteration 0 in 9 --
343bool(true)
344-- Inner iteration 1 in 9 --
345bool(true)
346-- Inner iteration 2 in 9 --
347bool(true)
348-- Inner iteration 3 in 9 --
349bool(true)
350-- Inner iteration 4 in 9 --
351bool(true)
352-- Inner iteration 5 in 9 --
353bool(true)
354-- Inner iteration 6 in 9 --
355bool(true)
356-- Inner iteration 7 in 9 --
357bool(true)
358-- Inner iteration 8 in 9 --
359bool(true)
360-- Inner iteration 9 in 9 --
361bool(true)
362-- Inner iteration 10 in 9 --
363bool(true)
364-- Inner iteration 11 in 9 --
365bool(true)
366-- Inner iteration 12 in 9 --
367bool(true)
368-- Inner iteration 13 in 9 --
369bool(true)
370
371*** Done ***
372