|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77595 concurrent processes prevent filesize() from working
Submitted: 2019-02-10 05:43 UTC Modified: 2019-02-10 21:29 UTC
From: Wes dot nospam at example dot org Assigned:
Status: Not a bug Package: *Directory/Filesystem functions
PHP Version: 7.2.15 OS: Windows
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: Wes dot nospam at example dot org
New email:
PHP Version: OS:


 [2019-02-10 05:43 UTC] Wes dot nospam at example dot org
other processes are denied to write the file while it is shared-locked, but attempting to do so prevents filesize() from working

Test script:

// create a file of 6 bytes
$path = __DIR__ . "/foo.txt";
file_put_contents($path, "123456");

// (1)
// open that file for read and shared-lock it
$file = fopen($path, "r");
flock($file, LOCK_SH | LOCK_NB);

// (2)
// attempt to write that file concurrently while the lock is active
echo `php -r "file_put_contents('$path', 'baz');"`;
// this step fails as expected -- means the file is still "123456"

// (3)
// attempt to read the file's size
clearstatcache(FALSE, $path);
$fileSize = filesize($path);
// should return 6 bytes but returns 0

// (4)
// this fails as consequence
echo $fileSize . "\n";
echo fread($file, $fileSize);

flock($file, LOCK_UN);

Expected result:
should work as if the step (2) was commented out


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-02-10 21:29 UTC]
-Status: Open +Status: Not a bug
 [2019-02-10 21:29 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Feb 25 23:01:33 2024 UTC