3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php touch("testfile"); function mylock() { $F1 = fopen("testfile","r"); if (flock($F1,LOCK_EX|LOCK_NB)) echo "First lock OK\n"; else echo "First lock FAIL\n"; $F2 = fopen("testfile","r"); if (flock($F2,LOCK_EX|LOCK_NB)) echo "Second lock OK\n"; else echo "Second lock FAIL\n"; } mylock(); echo "Function returned.\n"; mylock(); unlink("testfile");
Output for 5.0.0 - 7.1.0
Warning: touch(): Unable to create file testfile because Permission denied in /in/UjBS6 on line 2 Warning: fopen(testfile): failed to open stream: No such file or directory in /in/UjBS6 on line 5 Warning: flock() expects parameter 1 to be resource, boolean given in /in/UjBS6 on line 6 First lock FAIL Warning: fopen(testfile): failed to open stream: No such file or directory in /in/UjBS6 on line 7 Warning: flock() expects parameter 1 to be resource, boolean given in /in/UjBS6 on line 8 Second lock FAIL Function returned. Warning: fopen(testfile): failed to open stream: No such file or directory in /in/UjBS6 on line 5 Warning: flock() expects parameter 1 to be resource, boolean given in /in/UjBS6 on line 6 First lock FAIL Warning: fopen(testfile): failed to open stream: No such file or directory in /in/UjBS6 on line 7 Warning: flock() expects parameter 1 to be resource, boolean given in /in/UjBS6 on line 8 Second lock FAIL Warning: unlink(testfile): No such file or directory in /in/UjBS6 on line 15
Output for 4.3.2 - 4.4.9
Warning: touch(): Unable to create file testfile because Permission denied in /in/UjBS6 on line 2 Warning: fopen(testfile): failed to open stream: No such file or directory in /in/UjBS6 on line 5 Warning: flock(): supplied argument is not a valid stream resource in /in/UjBS6 on line 6 First lock FAIL Warning: fopen(testfile): failed to open stream: No such file or directory in /in/UjBS6 on line 7 Warning: flock(): supplied argument is not a valid stream resource in /in/UjBS6 on line 8 Second lock FAIL Function returned. Warning: fopen(testfile): failed to open stream: No such file or directory in /in/UjBS6 on line 5 Warning: flock(): supplied argument is not a valid stream resource in /in/UjBS6 on line 6 First lock FAIL Warning: fopen(testfile): failed to open stream: No such file or directory in /in/UjBS6 on line 7 Warning: flock(): supplied argument is not a valid stream resource in /in/UjBS6 on line 8 Second lock FAIL Warning: unlink(testfile): No such file or directory in /in/UjBS6 on line 15
Output for 4.3.1
Warning: touch() [http://www.php.net/function.touch]: Unable to create file testfile because Permission denied in /in/UjBS6 on line 2 Warning: fopen(testfile) [http://www.php.net/function.fopen]: failed to create stream: No such file or directory in /in/UjBS6 on line 5 Warning: flock(): supplied argument is not a valid stream resource in /in/UjBS6 on line 6 First lock FAIL Warning: fopen(testfile) [http://www.php.net/function.fopen]: failed to create stream: No such file or directory in /in/UjBS6 on line 7 Warning: flock(): supplied argument is not a valid stream resource in /in/UjBS6 on line 8 Second lock FAIL Function returned. Warning: fopen(testfile) [http://www.php.net/function.fopen]: failed to create stream: No such file or directory in /in/UjBS6 on line 5 Warning: flock(): supplied argument is not a valid stream resource in /in/UjBS6 on line 6 First lock FAIL Warning: fopen(testfile) [http://www.php.net/function.fopen]: failed to create stream: No such file or directory in /in/UjBS6 on line 7 Warning: flock(): supplied argument is not a valid stream resource in /in/UjBS6 on line 8 Second lock FAIL Warning: unlink(testfile) [http://www.php.net/function.unlink]: No such file or directory in /in/UjBS6 on line 15
Output for 4.3.0
Warning: touch() [http://www.php.net/function.touch]: Unable to create file testfile because Read-only file system in /in/UjBS6 on line 2 Warning: fopen(testfile) [http://www.php.net/function.fopen]: failed to create stream: No such file or directory in /in/UjBS6 on line 5 Warning: flock(): supplied argument is not a valid stream resource in /in/UjBS6 on line 6 First lock FAIL Warning: fopen(testfile) [http://www.php.net/function.fopen]: failed to create stream: No such file or directory in /in/UjBS6 on line 7 Warning: flock(): supplied argument is not a valid stream resource in /in/UjBS6 on line 8 Second lock FAIL Function returned. Warning: fopen(testfile) [http://www.php.net/function.fopen]: failed to create stream: No such file or directory in /in/UjBS6 on line 5 Warning: flock(): supplied argument is not a valid stream resource in /in/UjBS6 on line 6 First lock FAIL Warning: fopen(testfile) [http://www.php.net/function.fopen]: failed to create stream: No such file or directory in /in/UjBS6 on line 7 Warning: flock(): supplied argument is not a valid stream resource in /in/UjBS6 on line 8 Second lock FAIL Warning: unlink(testfile) [http://www.php.net/function.unlink]: Read-only file system in /in/UjBS6 on line 15