Bug #52895 [Opn->Nab]: require()/include()[once] ignores advisory file locking
Edit report at https://bugs.php.net/bug.php?id=52895&edit=1
ID: 52895
Updated by: requinix@php.net
Reported by: dan dot ponomarev at gmail dot com
Summary: require()/include()[once] ignores advisory file
locking
-Status: Open
+Status: Not a bug
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:
^ That.
Previous Comments:
------------------------------------------------------------------------
[2014-05-23 19:22:47] cmbecker69 at gmx dot de
Related To: Bug #52287
------------------------------------------------------------------------
[2014-05-23 19:05:24] 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.
------------------------------------------------------------------------
[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)