Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 24th, 2012  |  syntax: None  |  size: 0.41 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. LOCK FILE PHP for read then cannot be read?
  2. // ACQUIRE READ LOCK
  3. if(flock($file, LOCK_SH)) {
  4. // READ HASHES FILE
  5. if($contents = file('haasdas.txt')) {
  6.     // RELEASE READ LOCK
  7.     flock($file, LOCK_UN);
  8. } else {
  9.             echo 'errrrrrorzzzer';
  10.       }
  11. }
  12.        
  13. $fd=fopen($filename,'rb');
  14. while (!flock($fd,LOCK_SH)) usleep(500);
  15. $fs=fstat($fd);
  16. $contents=fread($fd,$fs['size']);
  17. flock($fd,LOCK_UN);
  18. fclose($fd);