| 
        php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
  [2010-09-20 20:06 UTC] dan dot ponomarev at gmail dot com
 Description: ------------ Require/include processes an input file immediatelly even it is locked with flock($file, LOCK_EX). This is causing problems when the target script generated dynamically by multiple concurrent threads. Tested on PHP 5.2.12, 5.2.14. Most likely this is a result of this bug fixation: http://bugs.php.net/bug.php? id=52287 . Test script: --------------- Create three files in the same dir. 1. locker.php: <?php $includand = dirname(__FILE__).'/includand.php'; $hfile = fopen($includand, 'r'); flock($hfile, LOCK_EX); sleep(20); flock(LOCK_UN); fclose($hfile); ?> 2. includer.php: <?php $includand = dirname(__FILE__).'/includand.php'; include($includand); ?> 3. includant.php <?php echo "HELLO"; ?> Launch locker.php in browser, then launch includer.php Expected result: ---------------- 'HELLO' as output of includer.php AFTER 20-seconds waiting. Actual result: -------------- 'HELLO' as output of includer.php IMMEDIATELY after run. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             
             | 
    |||||||||||||||||||||||||||||||||||||
            
                 
                Copyright © 2001-2025 The PHP GroupAll rights reserved.  | 
        Last updated: Tue Nov 04 06:00:01 2025 UTC | 
This is not a bug. flock() implements advisory file locking, so *every* script has to properly use flock(). In this case includer.php has to be something like the following: <?php $includand = dirname(__FILE__).'/includand.php'; $hfile = fopen($includand, 'r'); flock($hfile, LOCK_SH); include($includand); flock($hfile, LOCK_UN); fclose($includand); ?> Then the actual result matches the expected one.