php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61521 fopen uses stale data on symlinks - opens old file instead
Submitted: 2012-03-26 20:29 UTC Modified: 2016-08-26 13:46 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: jstephens at qualtrics dot com Assigned: cmb (profile)
Status: Not a bug Package: Filesystem function related
PHP Version: 5.3.10 OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jstephens at qualtrics dot com
New email:
PHP Version: OS:

 

 [2012-03-26 20:29 UTC] jstephens at qualtrics dot com
Description:
------------
After opening a symlink, PHP will always use the original link location, even if the link is externally modified during script execution.

Test script:
---------------
<?php
file_put_contents("linkOrig", "old data");
file_put_contents("linkNew", "new data");

//create the link
symlink("linkOrig", "link");
//`ln -s linkOrig link`;//this also works

file_get_contents("link");//open it and read it (caches the link data)

//simulate another program altering it
`ln -fs linkNew link`;

echo file_get_contents("link");


Expected result:
----------------
new data

Actual result:
--------------
old data

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-08-26 13:46 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2016-08-26 13:46 UTC] cmb@php.net
That is expected behavior due to the stat cache. Use
clearstatcache() if you have to read the symlink multiple times.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu May 08 11:01:27 2025 UTC