Bug #52895 [Com]: require()/include()[once] ignores advisory file locking

From: Date: Fri, 23 May 2014 19:05:26 +0000
Subject: Bug #52895 [Com]: require()/include()[once] ignores advisory file locking
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185912@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=52895&edit=1

 ID:                 52895
 Comment by:         cmbecker69 at gmx dot de
 Reported by:        dan dot ponomarev at gmail dot com
 Summary:            require()/include()[once] ignores advisory file
                     locking
 Status:             Open
 Type:               Bug
 Package:            Streams related
 Operating System:   Linux 2.6.9,2.6.18, WinXP
 PHP Version:        5.2.14
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2010-09-20 20:06:02] 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.


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=52895&edit=1


Thread (3 messages)

« previous php.bugs (#185912) next »