Bug->Doc #79017 [Opn->Ver]: Can delete files in use by other processes
| From: | cmb@php.net | Date: | Mon, 23 Dec 2019 10:24:45 +0000 |
| Subject: | Bug->Doc #79017 [Opn->Ver]: Can delete files in use by other processes | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-17165@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79017&edit=1
ID: 79017
Updated by: cmb@php.net
Reported by: asmanmmsj at gmail dot com
-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
Package: *Directory/Filesystem functions
Operating System: windows
-PHP Version: 7.4.1
+PHP Version: 7.3.0
Block user comment: N
Private report: N
New Comment:
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>
Previous Comments:
------------------------------------------------------------------------
[2019-12-22 05:40:26] 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:
--------------
-
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79017&edit=1