php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61121 get error result
Submitted: 2012-02-17 11:07 UTC Modified: 2012-02-17 17:14 UTC
From: gaoqiangscut at gmail dot com Assigned:
Status: Not a bug Package: POSIX related
PHP Version: Irrelevant OS: ubuntu
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: gaoqiangscut at gmail dot com
New email:
PHP Version: OS:

 

 [2012-02-17 11:07 UTC] gaoqiangscut at gmail dot com
Description:
------------
This is a bug in "stat" function, and I'm not quite sure which class this function belongs to.  Detailed message for the OS  and php version following:

OS message:
gao->:~$uname -a
Linux gaoqiang-VirtualBox 2.6.38-8-generic #42-Ubuntu SMP Mon Apr 11 03:31:50 UTC 2011 i686 i686 i386 GNU/Linux

php version:
gao->:~$php -v
PHP 5.3.5-1ubuntu7.4 with Suhosin-Patch (cli) (built: Dec 13 2011 18:25:14) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

Test script:
---------------
<?php 
$file="a.txt";
$fp=fopen($file,"a");
$st=stat($file);
echo "size= ";
echo $st["size"];
echo "\n";



fputs($fp,"test\n");
fclose($fp);


$st=stat($file);
echo "size= ";
echo $st["size"];
echo "\n";
?>

Expected result:
----------------
size=0
size=5

Actual result:
--------------
size=0
size=0

Patches

a.txt (last revision 2012-02-17 11:10 UTC by gaoqiangscut at gmail dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-02-17 17:14 UTC] rasmus@php.net
PHP has a stat cache for performance reasons. Add this line before your second 
stat() call and you will get your expected output:

clearstatcache(false,'a.txt');

If you read http://php.net/stat you will see it says:

"Note: The results of this function are cached. See clearstatcache() for more 
details."
 [2012-02-17 17:14 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC