|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52895 require()/include()[once] ignores advisory file locking
Submitted: 2010-09-20 20:06 UTC Modified: 2014-11-10 23:53 UTC
Avg. Score:4.3 ± 1.1
Reproduced:9 of 9 (100.0%)
Same Version:6 (66.7%)
Same OS:5 (55.6%)
From: dan dot ponomarev at gmail dot com Assigned:
Status: Not a bug Package: Streams related
PHP Version: 5.2.14 OS: Linux 2.6.9,2.6.18, WinXP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: dan dot ponomarev at gmail dot com
New email:
PHP Version: OS:


 [2010-09-20 20:06 UTC] dan dot ponomarev at gmail dot com
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:
id=52287 .

Test script:
Create three files in the same dir.

1. locker.php:
    $includand = dirname(__FILE__).'/includand.php';
    $hfile = fopen($includand, 'r');
    flock($hfile, LOCK_EX);

2. includer.php:
    $includand = dirname(__FILE__).'/includand.php';

3. includant.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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-23 19:05 UTC] cmbecker69 at gmx dot de
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:

        $includand = dirname(__FILE__).'/includand.php';
        $hfile = fopen($includand, 'r');
        flock($hfile, LOCK_SH);
        flock($hfile, LOCK_UN);
Then the actual result matches the expected one.
 [2014-11-10 23:53 UTC]
-Status: Open +Status: Not a bug
 [2014-11-10 23:53 UTC]
^ That.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Dec 03 12:01:27 2023 UTC