php.net |  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
Votes:9
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
 [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.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

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:

      <?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.
 [2014-11-10 23:53 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2014-11-10 23:53 UTC] requinix@php.net
^ That.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 09:01:28 2024 UTC