Hello php-general,

Script flock.php:
<?
 $file_name = 'flock.txt';

 for($i=0;$i<1000;$i++){
   if ($fd = fopen($file_name,'a+')){
     if (flock($fd,LOCK_EX)){
        fseek($fd,0,SEEK_END);
        fwrite($fd,$i.' : '.$i."\n");
        flock($fd,LOCK_UN);
     }else{
       die('Can not lock file');
     }
     fclose($fd);
   }else{
     echo 'Can not open file';
   }
 }
?>

Run it: ab -n 10 -c 10 http://host/flock.php

Why file have similar lines ?

432 : 431 : 431
432
433 : 433
...
84841 : 841
2 : 842

May be flock not working or I do not understand, how it should work ?
How correctly to write in a file from different threads?

P.S I use Linux-2.2.17+PHP4.0.4pl1

Best regards,
 Andrew Sitnikov                         
 e-mail : [EMAIL PROTECTED]
 GSM: (+372) 56491109



-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to