fork download
  1. <?php
  2.  
  3. $fp = fopen("/tmp/lock.txt","w+");
  4. if(flock($fp, LOCK_EX)){// 进行排它型锁定
  5. fwrite($fp,"Write something here\n");
  6. flock($fp, LOCK_UN);// 释放锁定
  7. }else{
  8. echo "Couldn't lock the file !";
  9. }
  10. fclose($fp);
Success #stdin #stdout #stderr 0.03s 52432KB
stdin
Standard input is empty
stdout
Couldn't lock the file !
stderr
PHP Warning:  fopen(/tmp/lock.txt): failed to open stream: Permission denied in /home/vkg6AA/prog.php on line 3
PHP Warning:  flock() expects parameter 1 to be resource, boolean given in /home/vkg6AA/prog.php on line 4
PHP Warning:  fclose() expects parameter 1 to be resource, boolean given in /home/vkg6AA/prog.php on line 10