Test if file is locked

Viewed 13870

In PHP, how can I test if a file has already been locked with flock? For example, if another running script has called the following:

$fp = fopen('thefile.txt', 'w');
flock($fp, LOCK_EX);
3 Answers
if(stream_get_meta_data($fp)['blocked'])
  echo 'file is locked';
else 
  echo 'file is not locked';
Related