From:
Operating system: Windows
PHP version: 5.2.13
Package: Streams related
Bug Type: Bug
Bug description:You cannot delete a locked file on Windows
Description:
------------
A script creates files. To make sure that no "reader" is accessing the file
while
the script is changing its content (think of a cache!), you will use
flock() to
secure the progress.
Tested with PHP Version 5.2.12 (CGI/FastCGI), latest Zend Server release.
Test script:
---------------
<?php
// Set a plain text header
header('Content-Type: text/plain; charset=iso-8859-1');
header('X-Content-Type-Options: nosniff');
$tempFile = tempnam(sys_get_temp_dir(), 'lTest');
if ($tempFile === FALSE)
{
die('Temp file creation failed!');
}
else
{
echo 'Our temp file will be: ' . $tempFile . PHP_EOL;
}
$fh = fopen($tempFile, 'w');
if ($fh === FALSE)
{
die('Cannot get file handler!');
}
$lock = flock($fh, LOCK_EX);
if ($lock === FALSE)
{
die('Cannot get file lock!');
}
unlink($tempFile);
clearstatcache();
if (file_exists($tempFile) === TRUE)
{
die('I was unable to delete the file!');
}
$lock = flock($fh, LOCK_UN);
if ($lock === FALSE)
{
die('Unable to release lock!');
}
fclose($fh);
echo 'Successful! We created a temp file, which we deleted, while the file
was locked!' . PHP_EOL;
Expected result:
----------------
I expect that it will work in Windows, like it is working on Linux.
If this isn't possible, it should be documented.
Actual result:
--------------
It will work fine on Linux, but on Windows it will raise a "SHARING
VIOLATION"
(trace it in "Process Monitor" from SysInternals).
--
Edit bug report at http://bugs.php.net/bug.php?id=51227&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=51227&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=51227&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=51227&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=51227&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=51227&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=51227&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=51227&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=51227&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=51227&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=51227&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=51227&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=51227&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=51227&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=51227&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51227&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=51227&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=51227&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=51227&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=51227&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=51227&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=51227&r=mysqlcfg