|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52287 REQUIRE_ONCE,REQUIRE,INCLUDE & INCLUDE_ONCE do not handle flock correctly
Submitted: 2010-07-08 11:41 UTC Modified: 2014-12-30 10:41 UTC
Avg. Score:4.8 ± 0.4
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:0 (0.0%)
From: raat1979 at gmail dot com Assigned:
Status: No Feedback Package: *Directory/Filesystem functions
PHP Version: Irrelevant OS: Windows Server 2003
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: raat1979 at gmail dot com
New email:
PHP Version: OS:


 [2010-07-08 11:41 UTC] raat1979 at gmail dot com
When an exclusive lock is set on a file (flock) importing the file from any script (including the script itself) with require,require_once,include or .
include_once silently fails and imports nothing. 
Trying to lock the file from the same script works as expected.

Test script:
<?php //setLock.php
$theFile = fopen('thefile.html', 'rb'); //template file
flock($theFile, LOCK_EX); //accuire an exclusive lock on the file
echo(require('someFile'));       <-- this silently fails
flock($theFile, LOCK_UN );//release the lock
echo(require('someFile'));       <-- this succeeds
phpinfo(); ?>
<?php //getTheLockedFile.php
echo(require('someFile');) <-- this silently fails

Expected result:
When excecuting setlock.php I expect it to succeed on both instances or die with the first require attempt

when simultaneously excecuting getTheLockedFile.php I expect excecution to be halted untill the setLock.php file completes or to die with an error.

Actual result:
When excecuting setlock.php the first require attempt fails silently (return 
value 1, no error) the seccond attempt succeeds as normal.

when simultaneously excecuting getTheLockedFile.php the require attempt fails silently (return value 1, no error)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-23 19:22 UTC] cmbecker69 at gmx dot de
I have slightly rewritten the test script setlock.php to make sure
that it is the file that should be locked that is require'd, and
to improve the output:


    $theFile = fopen('thefile.html', 'rb');
    flock($theFile, LOCK_EX);
    var_dump(require 'thefile.html');
    flock($theFile, LOCK_UN);
    var_dump(require 'thefile.html');


For me (PHP 5.4.19, Win 7, API20100525,TS,VC9) both require
statements succeed, what is what I'd expect (as require doesn't
heed any advisory locks).

Regarding the second script see my comment on bug #52895

IMO this is not a bug.
 [2014-11-10 23:56 UTC]
-Status: Open +Status: Feedback
 [2014-11-10 23:56 UTC]
In case there's still interest in this ticket,

raat1979, the script you gave needs distinct filenames in there to make sense, not just "thefile.html" and "someFile". Is what cmbecker69 posted like the code you're talking about? Or is it something else?
 [2014-12-30 10:41 UTC] php-bugs at lists dot php dot net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Re-Opened". Thank you.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Sep 19 15:03:37 2021 UTC