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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
38 - 1 = ?
Subscribe to this entry?

 
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 30 04:01:30 2024 UTC