Example 1 — Check a Real File Stream
Open a temp file and ask whether locking is supported.
<?php
$path = sys_get_temp_dir() . '/codetofun_lock.txt';
$stream = fopen($path, 'c+');
echo stream_supports_lock($stream) ? 'lock ok' : 'no lock', PHP_EOL;
fclose($stream);
unlink($path); How It Works
- fopen() opens a real file.
- stream_supports_lock() returns true for typical files.
- You may then call flock() safely.
- Clean up the demo file.

