ID: 41769 Updated by: [EMAIL PROTECTED] Reported By: commander at graphicore dot de -Status: Open +Status: Closed Bug Type: Documentation problem Operating System: WinXP PHP Version: 4.4.7 New Comment:
This bug has been fixed in the documentation's XML sources. Since the online and downloadable versions of the documentation need some time to get updated, we would like to ask you to be a bit patient. Thank you for the report, and for helping us make our documentation better. "LOCK_NB not supported on Windows" Previous Comments: ------------------------------------------------------------------------ [2007-06-25 17:56:19] [EMAIL PROTECTED] Seems to be docu problem, reclassified as such. ------------------------------------------------------------------------ [2007-06-21 18:52:55] commander at graphicore dot de Little typo: with "LOCK_EX + LOCK_NB" OR "LOCK_SH + LOCK_NB" ------------------------------------------------------------------------ [2007-06-21 18:23:02] commander at graphicore dot de Description: ------------ Different behaviors of flock between WinXp and Linux(and FreeBSD) if you use the optional third Argument ($wouldblock) with "LOCK_EX + LOCK_NB" OR "LOCK_EX + LOCK_NB" If this is no bug please correct the documentation. Versions of PHP tested Win: PHP 4.4.4 PHP 4.4.7 PHP 5.1.6 PHP 5.2.2 (all Windows versions do the same) Linux PHP 4.4.4 FreeBSD PHP 4.4.6 (both Linux and FreeBSD do the same) Reproduce code: --------------- <?php /* Here's my Code, run it from two different browsers or from two different files because if you request the same file twice at the same time modern browsers wait for the first request to finish until sending the seccond.(IE7 does not wait therefore its not modern): */ $starttime = time(); $date = date('h:i:s',$starttime); echo 'start:'.$date.'<br />'; $handle = fopen('test.txt','ab'); if($handle){ $wouldblock = NULL; $flock = flock($handle,LOCK_EX + LOCK_NB,$wouldblock); echo '$flock '; var_dump($flock);echo '<br />'; echo '$woulblock '; var_dump($wouldblock);echo '<br />'; if(!$flock){ echo 'no lock for me<br />'; }else{ echo 'got a lock<br />'; fwrite( $handle, ' start '.$date.' ' ); sleep(5); //assume the whole writing process takes 5 seconds fwrite( $handle, ' end '.$date."\n" ); } fclose($handle); } echo 'end: this took '.(time()-$starttime).' secconds'; ?> Expected result: ---------------- Linux will if the file is locked set $wouldblock to int(1) and always return TRUE. Output Linux (and FreeBSD): ###first process: start:06:05:09 $flock bool(true) $woulblock int(0) got a lock end: this took 5 secconds ###seccond Process: start:06:05:11 $flock bool(true) $woulblock int(1) got a lock end: this took 5 secconds ###test.txt start 06:05:09 start 06:05:11 end 06:05:09 end 06:05:11 Actual result: -------------- Windows will set $wouldblock always to int(0) and if the file is locked return FALSE. Output WinXp: ###first process: start:06:09:22 $flock bool(true) $woulblock int(0) got a lock end: this took 5 secconds ###seccond Process: start:06:09:24 $flock bool(false) $woulblock int(0) no lock for me end: this took 0 secconds ###test.txt start 06:09:22 end 06:09:22 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=41769&edit=1