php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #79017 Can delete files in use by other processes
Submitted: 2019-12-22 05:40 UTC Modified: 2019-12-29 12:47 UTC
From: asmanmmsj at gmail dot com Assigned: cmb (profile)
Status: Closed Package: *Directory/Filesystem functions
PHP Version: 7.3.0 OS: windows
Private report: No CVE-ID: None
 [2019-12-22 05:40 UTC] asmanmmsj at gmail dot com
Description:
------------
hi
file_exists() return false on locked file with flock()!!
its ok on php 7.2 but after that its have problem...

just run this test file 2 time 
in second time its not detect file exist because its locked with flock()

Test script:
---------------
 <?php
error_reporting(0);
echo unlink("test.txt");
echo "<=unlink\r\n";
echo "\r\n>";
echo $exist = file_exists("test.txt");<<=== bug is here
echo "<=exist\r\n";
if ($exist)
{
   echo "!!!";
   echo "\r\n";
   sleep(1111);
   //exit();
}
echo "\r\n>";
echo $file = fopen("test.txt","w+");
echo "<=fopn\r\n";

// exclusive lock
echo "\r\n>";
echo $lockkk = flock($file,LOCK_EX);
echo "<=lock\r\n";
if ($lockkk) {
	 echo ">";
  echo fwrite($file,"Add some text to the file.");
  echo "<=fwrite\r\n";
  echo ">";
  echo fflush($file);
  echo "<=fflush\r\n";
  sleep(1000);
  // release lock
  flock($file,LOCK_UN);
} else {
  echo "Error locking file!";
}
echo "end:";
echo fclose($file);
sleep(100);
?> 

Expected result:
----------------
fisrt run (and lock text.txt) sleep...
result : 
><=unlink

><=exist

>Resource id #5<=fopn

>1<=lock
>26<=fwrite
>1<=fflush

second run (file already lock..)
>1<=unlink

><=exist

><=fopn

><=lock
Error locking file!end:

OK result in php 7.2 :
><=unlink

>1<=exist
!!!

Actual result:
--------------
-

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-12-23 10:24 UTC] cmb@php.net
-Summary: file_exists() return false on file flock() +Summary: Can delete files in use by other processes -Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem -PHP Version: 7.4.1 +PHP Version: 7.3.0
 [2019-12-23 10:24 UTC] cmb@php.net
The behavior changed due to commit 17d621e[1], as of which all
files are opened with the FILE_SHARE_DELETE flag set.  This is
closer to POSIX semantics than before[2], but due to some platform
differences it is not identical.

file_exists() returning false for the second process is actually
correct; although the file is still there because the first
process has an open handle to it, the file is no longer supposed
to be accessible by the second process (even opening for reading
would fail). The difference to POSIX behavior is that the second
process can't even open the file for writing, but locking would
neither work on POSIX.

From the PHP side, I see this as documentation issue (while the
migration guide hints at the behavioral change, it has to be
clarified in the manual proper).  With regard to the test script,
I think it is generally an error to delete lock files which may
have a lock on them; instead use a separate lock file, if
necessary.

[1] <http://git.php.net/?p=php-src.git;a=commit;h=17d621e7d3bc0a97d1ddddeb3e7fbdea25548637>
[2] <https://www.php.net/manual/en/migration73.windows-support.php#migration73.windows-support.core.file-descriptors>
 [2019-12-29 12:46 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=348727
Log: Fix #79017: Can delete files in use by other processes
 [2019-12-29 12:47 UTC] cmb@php.net
-Status: Verified +Status: Closed -Assigned To: +Assigned To: cmb
 [2019-12-29 12:47 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2019-12-29 12:50 UTC] salathe@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=3ced2726b7a73c6eea9cdc830c244fcbfd16ab36
Log: Fix #79017: Can delete files in use by other processes
 [2019-12-30 09:35 UTC] mumumu@php.net
Automatic comment from SVN on behalf of mumumu
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=348732
Log: Fix #79017: Can delete files in use by other processes

Bug: https://bugs.php.net/79017 (Verified) Can delete files in use by other processes
 [2020-02-07 06:04 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=19822bcfa1292e05f215372012d5611651905070
Log: Fix #79017: Can delete files in use by other processes
 [2020-12-30 11:59 UTC] nikic@php.net
Automatic comment on behalf of mumumu
Revision: http://git.php.net/?p=doc/ja.git;a=commit;h=6696515db3fa2bf057a1f7ebec7dd79626e0c900
Log: Fix #79017: Can delete files in use by other processes
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC