3v4l.org

run code in 300+ PHP versions simultaneously
<?php $path = "/tmp/foo.txt"; file_put_contents($path, "123456"); $file = fopen($path, "r"); flock($file, LOCK_SH | LOCK_NB); `php -r "var_dump(file_put_contents('$file', 'baz'));"`; // should fail because locked clearstatcache(FALSE, $path); $fileSize = filesize($path); // should return 6 bytes but returns 0 echo $fileSize . "\n"; $contents = fread($file, $fileSize); flock($file, LOCK_UN); fclose($file); echo $contents;

preferences:
19.97 ms | 411 KiB | 5 Q