php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76877 file_exists() don't see hosts file
Submitted: 2018-09-13 13:13 UTC Modified: 2018-09-14 11:42 UTC
From: dominique at ottello dot net Assigned: cmb (profile)
Status: Not a bug Package: *General Issues
PHP Version: 7.3.0RC1 32bit OS: Windows 7 64bit
Private report: No CVE-ID: None
 [2018-09-13 13:13 UTC] dominique at ottello dot net
Description:
------------
PHP 7.3.0rc1 32 bit on Windows 7 64 bit
Return false for
file_exists('c:/windows/system32/drivers/etc/hosts');
or
is_writable('c:/windows/system32/drivers/etc/hosts');
although we can open this file or take its content by file() or file_get_contents() and even modify it with fwrite().

I have never encountered this problem with any other version of PHP, including 7.2.10 32 bit.
I went back to the first version PHP 7.3.0alpha2 which has the same problem.


Test script:
---------------
$c_hostsFile = str_replace("\\","/",getenv('WINDIR').'/system32/drivers/etc/hosts');
// Check file_exists
$i = 1;
$def = 0;
do {
	clearstatcache();
	if(!file_exists($c_hostsFile)) {
		echo "File ".$c_hostsFile." DOES NOT EXISTS - Test number ".$i."<br>";
		$def++;
	}
	$del = rand(100,500)*1000;
	//echo "Test number ".$i." Delay ".($del/1000)." ms<br>";
	usleep($del);
	$i++;
} while ($i < 100 && $def < 10);
echo $i." tests<br>";


Expected result:
----------------
--- Windows NT 6.1 build 7601 (Windows 7 Professional Edition Service Pack 1) x64 64bit---
--- Serveur Apache/2.4.34 (Win32) PHP/7.3.0RC1 ---
--- PHP version 7.3.0RC1 32bit ----
100 tests


Actual result:
--------------
--- Windows NT 6.1 build 7601 (Windows 7 Professional Edition Service Pack 1) x64 64bit---
--- Serveur Apache/2.4.34 (Win32) PHP/7.3.0RC1 ---
--- PHP version 7.3.0RC1 32bit ----
File C:/Windows/system32/drivers/etc/hosts DOES NOT EXISTS - Test number 1
File C:/Windows/system32/drivers/etc/hosts DOES NOT EXISTS - Test number 2
File C:/Windows/system32/drivers/etc/hosts DOES NOT EXISTS - Test number 3
File C:/Windows/system32/drivers/etc/hosts DOES NOT EXISTS - Test number 4
File C:/Windows/system32/drivers/etc/hosts DOES NOT EXISTS - Test number 5
File C:/Windows/system32/drivers/etc/hosts DOES NOT EXISTS - Test number 6
File C:/Windows/system32/drivers/etc/hosts DOES NOT EXISTS - Test number 7
File C:/Windows/system32/drivers/etc/hosts DOES NOT EXISTS - Test number 8
File C:/Windows/system32/drivers/etc/hosts DOES NOT EXISTS - Test number 9
File C:/Windows/system32/drivers/etc/hosts DOES NOT EXISTS - Test number 10
11 tests


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-09-13 17:09 UTC] ab@php.net
-Status: Open +Status: Feedback
 [2018-09-13 17:09 UTC] ab@php.net
Thanks for the report. I'm not able to reproduce the behavior using the provided snippet. Even with 1000 runs it matches the expected behavior. Some environment issue might be involved, like some other program sharing same port, etc. Could you check that, please?

Thanks.
 [2018-09-14 11:32 UTC] dominique at ottello dot net
-Status: Feedback +Status: Open -PHP Version: 7.3.0RC1 +PHP Version: 7.3.0RC1 32bit
 [2018-09-14 11:32 UTC] dominique at ottello dot net
Hi,
Last night, I spent more than four hours doing a lot of testing, checking access rights to the folders and files involved without finding anything conclusive. Always the error "file not exists" only with PHP 7.3.0RC1 32 bit under Windows 7 64 bit.
No problem with PHP 7.3.0RC1 64-bit under Windows 7 64-bit, nor with all versions of PHP 32 and 64-bit (PHP7.3.0RC1 including), but under Windows10.

This morning, there were updates for Windows 7 and Windows 10 and I only resumed testing after these updates.
And, as if by a miracle, no more "file not exists" errors.
Miracles do not exist in computing, so I deduce that this update of Windows 7 64bit fixed something that had been broken previously, perhaps by a previous update.

Sorry for all this inconvenience, but it was still extremely strange that this problem was only seen by PHP 7.3.0 32bit and never by any other version of PHP.

So it wasn't a bug....
 [2018-09-14 11:42 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2018-09-14 11:42 UTC] cmb@php.net
Great that the issue has been resolved! :)
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Fri Nov 16 03:01:26 2018 UTC