|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-08-23 15:03 UTC] glen at delfi dot ee
Description:
------------
$ strace php -r 'for ($i=0;$i<5;$i++)
{$fp=fopen("/home/glen/tmp/php/long/test/dir/is/here/$i","w");fclose($fp);}'
2>&1 |grep /home
this will call lstat64() each time on:
/home
/home/glen
/home/glen/tmp
/home/glen/tmp/php
/home/glen/tmp/php/long
/home/glen/tmp/php/long/test
/home/glen/tmp/php/long/test/dir
/home/glen/tmp/php/long/test/dir/is
/home/glen/tmp/php/long/test/dir/is/here
while it should either don't do them at all or at least
cache the paths that haven't been altered (i only write to
last dir)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 21:00:02 2025 UTC |
➔ php -r 'var_dump(ini_get("open_basedir"));' Command line code:1: string(0) ""➔ php --version PHP 5.6.27 (cli) (built: Nov 21 2016 23:08:15) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies with Xdebug v2.4.1, Copyright (c) 2002-2016, by Derick Rethans ➔ php -r 'var_dump(ini_get("open_basedir"));' Command line code:1: string(0) "" ➔ strace php -r 'for ($i=0;$i<5;$i++) {$fp=fopen("/home/glen/tmp/php/long/test/dir/is/here/$i","w");fclose($fp);}' 2>&1 |grep /home open("/home/glen/.config/ImageMagick/log.xml", O_RDONLY) = -1 ENOENT (No such file or directory) open("/home/glen/.magick/log.xml", O_RDONLY) = -1 ENOENT (No such file or directory) open("/home/glen/.config/ImageMagick/policy.xml", O_RDONLY) = -1 ENOENT (No such file or directory) open("/home/glen/.magick/policy.xml", O_RDONLY) = -1 ENOENT (No such file or directory) open("/home/glen/.krb5/config", O_RDONLY) = -1 ENOENT (No such file or directory) stat("/home/glen/.snmp", 0x7ffcda428cf0) = -1 ENOENT (No such file or directory) stat("/home/glen/.snmp", 0x7ffcda428cf0) = -1 ENOENT (No such file or directory) stat("/home/glen/.snmp/tls/ca-certs", 0x7ffcda426870) = -1 ENOENT (No such file or directory) stat("/home/glen/.snmp/tls/certs", 0x7ffcda426870) = -1 ENOENT (No such file or directory) stat("/home/glen/.snmp/tls/private", 0x7ffcda426870) = -1 ENOENT (No such file or directory) open("/home/glen/.snmp/mibs", O_RDONLY|O_NONBLOCK|O_DIRECTORY|O_CLOEXEC) = -1 ENOENT (No such file or directory) stat("/home/glen/.snmp", 0x7ffcda428d00) = -1 ENOENT (No such file or directory) stat("/home/glen/.snmp", 0x7ffcda428d00) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is/here/0", 0x7ffcda426c80) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is/here", 0x7ffcda426ae0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is", 0x7ffcda426940) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir", 0x7ffcda4267a0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test", 0x7ffcda426610) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long", 0x7ffcda426480) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php", 0x7ffcda4262f0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp", {st_mode=S_IFDIR|0700, st_size=4096, ...}) = 0 lstat("/home/glen", {st_mode=S_IFDIR|0775, st_size=12288, ...}) = 0 lstat("/home", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 open("/home/glen/tmp/php/long/test/dir/is/here/0", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 ENOENT (No such file or directory) write(2, "PHP Warning: fopen(/home/glen/t"..., 145PHP Warning: fopen(/home/glen/tmp/php/long/test/dir/is/here/0): failed to open stream: No such file or directory in Command line code on line 1 lstat("/home/glen/tmp/php/long/test/dir/is/here/1", 0x7ffcda426c80) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is/here", 0x7ffcda426ae0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is", 0x7ffcda426940) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir", 0x7ffcda4267a0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test", 0x7ffcda426610) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long", 0x7ffcda426480) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php", 0x7ffcda4262f0) = -1 ENOENT (No such file or directory) open("/home/glen/tmp/php/long/test/dir/is/here/1", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 ENOENT (No such file or directory) write(2, "PHP Warning: fopen(/home/glen/t"..., 145PHP Warning: fopen(/home/glen/tmp/php/long/test/dir/is/here/1): failed to open stream: No such file or directory in Command line code on line 1 lstat("/home/glen/tmp/php/long/test/dir/is/here/2", 0x7ffcda426c80) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is/here", 0x7ffcda426ae0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is", 0x7ffcda426940) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir", 0x7ffcda4267a0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test", 0x7ffcda426610) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long", 0x7ffcda426480) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php", 0x7ffcda4262f0) = -1 ENOENT (No such file or directory) open("/home/glen/tmp/php/long/test/dir/is/here/2", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 ENOENT (No such file or directory) write(2, "PHP Warning: fopen(/home/glen/t"..., 145PHP Warning: fopen(/home/glen/tmp/php/long/test/dir/is/here/2): failed to open stream: No such file or directory in Command line code on line 1 lstat("/home/glen/tmp/php/long/test/dir/is/here/3", 0x7ffcda426c80) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is/here", 0x7ffcda426ae0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is", 0x7ffcda426940) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir", 0x7ffcda4267a0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test", 0x7ffcda426610) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long", 0x7ffcda426480) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php", 0x7ffcda4262f0) = -1 ENOENT (No such file or directory) open("/home/glen/tmp/php/long/test/dir/is/here/3", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 ENOENT (No such file or directory) write(2, "PHP Warning: fopen(/home/glen/t"..., 145PHP Warning: fopen(/home/glen/tmp/php/long/test/dir/is/here/3): failed to open stream: No such file or directory in Command line code on line 1 lstat("/home/glen/tmp/php/long/test/dir/is/here/4", 0x7ffcda426c80) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is/here", 0x7ffcda426ae0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is", 0x7ffcda426940) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir", 0x7ffcda4267a0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test", 0x7ffcda426610) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long", 0x7ffcda426480) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php", 0x7ffcda4262f0) = -1 ENOENT (No such file or directory) open("/home/glen/tmp/php/long/test/dir/is/here/4", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 ENOENT (No such file or directory) write(2, "PHP Warning: fopen(/home/glen/t"..., 145PHP Warning: fopen(/home/glen/tmp/php/long/test/dir/is/here/4): failed to open stream: No such file or directory in Command line code on line 1i do not see any improvement, no matter what php version or cache size is. post your result proving otherwise, maybe there's something hidden in plain sight. ➔ php70 -i|grep realpath_cache_size realpath_cache_size => 4096K => 4096K ➔ php70 -d realpath_cache_size=128000k -i|grep realpath_cache_size realpath_cache_size => 128000k => 128000k ➔ php70 -d realpath_cache_size=128000k --version PHP 7.0.18 (cli) (built: Apr 24 2017 20:13:36) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies ➔ strace php70 -d realpath_cache_size=128000k -r 'for ($i=0;$i<5;$i++) {$fp=fopen("/home/glen/tmp/php/long/test/dir/is/here/$i","w");fclose($fp);}' 2>&1 |grep /home lstat("/home/glen/.local/npm/bin/php70", 0x7fff98552520) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is/here/0", 0x7fff98551160) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is/here", 0x7fff98550fc0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is", 0x7fff98550e20) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir", 0x7fff98550c80) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test", 0x7fff98550af0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long", 0x7fff98550960) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php", 0x7fff985507d0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp", {st_mode=S_IFDIR|0700, st_size=4096, ...}) = 0 lstat("/home/glen", {st_mode=S_IFDIR|0775, st_size=12288, ...}) = 0 lstat("/home", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 open("/home/glen/tmp/php/long/test/dir/is/here/0", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 ENOENT (No such file or directory) write(2, "PHP Warning: fopen(/home/glen/t"..., 145PHP Warning: fopen(/home/glen/tmp/php/long/test/dir/is/here/0): failed to open stream: No such file or directory in Command line code on line 1 lstat("/home/glen/tmp/php/long/test/dir/is/here/1", 0x7fff98551160) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is/here", 0x7fff98550fc0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is", 0x7fff98550e20) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir", 0x7fff98550c80) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test", 0x7fff98550af0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long", 0x7fff98550960) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php", 0x7fff985507d0) = -1 ENOENT (No such file or directory) open("/home/glen/tmp/php/long/test/dir/is/here/1", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 ENOENT (No such file or directory) write(2, "PHP Warning: fopen(/home/glen/t"..., 145PHP Warning: fopen(/home/glen/tmp/php/long/test/dir/is/here/1): failed to open stream: No such file or directory in Command line code on line 1 lstat("/home/glen/tmp/php/long/test/dir/is/here/2", 0x7fff98551160) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is/here", 0x7fff98550fc0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is", 0x7fff98550e20) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir", 0x7fff98550c80) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test", 0x7fff98550af0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long", 0x7fff98550960) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php", 0x7fff985507d0) = -1 ENOENT (No such file or directory) open("/home/glen/tmp/php/long/test/dir/is/here/2", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 ENOENT (No such file or directory) write(2, "PHP Warning: fopen(/home/glen/t"..., 145PHP Warning: fopen(/home/glen/tmp/php/long/test/dir/is/here/2): failed to open stream: No such file or directory in Command line code on line 1 lstat("/home/glen/tmp/php/long/test/dir/is/here/3", 0x7fff98551160) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is/here", 0x7fff98550fc0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is", 0x7fff98550e20) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir", 0x7fff98550c80) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test", 0x7fff98550af0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long", 0x7fff98550960) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php", 0x7fff985507d0) = -1 ENOENT (No such file or directory) open("/home/glen/tmp/php/long/test/dir/is/here/3", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 ENOENT (No such file or directory) write(2, "PHP Warning: fopen(/home/glen/t"..., 145PHP Warning: fopen(/home/glen/tmp/php/long/test/dir/is/here/3): failed to open stream: No such file or directory in Command line code on line 1 lstat("/home/glen/tmp/php/long/test/dir/is/here/4", 0x7fff98551160) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is/here", 0x7fff98550fc0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir/is", 0x7fff98550e20) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test/dir", 0x7fff98550c80) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long/test", 0x7fff98550af0) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php/long", 0x7fff98550960) = -1 ENOENT (No such file or directory) lstat("/home/glen/tmp/php", 0x7fff985507d0) = -1 ENOENT (No such file or directory) open("/home/glen/tmp/php/long/test/dir/is/here/4", O_WRONLY|O_CREAT|O_TRUNC, 0666) = -1 ENOENT (No such file or directory) write(2, "PHP Warning: fopen(/home/glen/t"..., 145PHP Warning: fopen(/home/glen/tmp/php/long/test/dir/is/here/4): failed to open stream: No such file or directory in Command line code on line 1 ➔> i do not see any improvement, no matter what php version or cache size is. Ah, I should have looked more carefully. Sorry! The issue is that if a dirent does not exists (ENOENT), the realpath cache doesn't cache this info, because the dirent may be created before the next lookup. > From the strace it looks like we're still stat'ing all path components, even > though the full path is already not found. Apparently, we're stat'ting from bottom to top for whatever reason: strace sapi/cli/php -r 'for ($i=0;$i<5;$i++) {$fp=fopen("/home/vagrant/$i","w");fclose($fp);}' 2>&1 |grep /vagrant prints lstat("/home/vagrant/0", 0x7ffe7a4f6f90) = -1 ENOENT (No such file or directory) lstat("/home/vagrant", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 open("/home/vagrant/0", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3 lstat("/home/vagrant/1", 0x7ffe7a4f6f90) = -1 ENOENT (No such file or directory) open("/home/vagrant/1", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3 lstat("/home/vagrant/2", 0x7ffe7a4f6f90) = -1 ENOENT (No such file or directory) open("/home/vagrant/2", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3 lstat("/home/vagrant/3", 0x7ffe7a4f6f90) = -1 ENOENT (No such file or directory) open("/home/vagrant/3", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3 lstat("/home/vagrant/4", 0x7ffe7a4f6f90) = -1 ENOENT (No such file or directory) open("/home/vagrant/4", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3> Apparently, we're stat'ting from bottom to top for whatever reason: The reason is that we have to resolve links first. Anyhow, I don't see a real problem here. If a nested directory structure is accessed where parents don't exist, there are superfluous stat() calls. However, accessing such a structure doesn't make sense in the first place, and appears to be a programming error. If all parent directories already exist, there are no superfluous stat() calls. Consider: $ ls /home/vagrant $ strace sapi/cli/php -r 'for ($i=0;$i<5;$i++) {$fp=fopen("/home/vagrant/foo/bar/baz/$i","w");fclose($fp);}' 2>&1 | grep 'lstat("/home/vagrant' lstat("/home/vagrant/foo/bar/baz/0", 0x7ffc13cd4560) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo/bar/baz", 0x7ffc13cd4450) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo/bar", 0x7ffc13cd4340) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo", 0x7ffc13cd4230) = -1 ENOENT (No such file or directory) lstat("/home/vagrant", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/home/vagrant/foo/bar/baz/1", 0x7ffc13cd4560) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo/bar/baz", 0x7ffc13cd4450) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo/bar", 0x7ffc13cd4340) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo", 0x7ffc13cd4230) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo/bar/baz/2", 0x7ffc13cd4560) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo/bar/baz", 0x7ffc13cd4450) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo/bar", 0x7ffc13cd4340) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo", 0x7ffc13cd4230) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo/bar/baz/3", 0x7ffc13cd4560) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo/bar/baz", 0x7ffc13cd4450) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo/bar", 0x7ffc13cd4340) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo", 0x7ffc13cd4230) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo/bar/baz/4", 0x7ffc13cd4560) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo/bar/baz", 0x7ffc13cd4450) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo/bar", 0x7ffc13cd4340) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo", 0x7ffc13cd4230) = -1 ENOENT (No such file or directory) $ mkdir -p /home/vagrant/foo/bar/baz $ strace sapi/cli/php -r 'for ($i=0;$i<5;$i++) {$fp=fopen("/home/vagrant/foo/bar/baz/$i","w");fclose($fp);}' 2>&1 | grep 'lstat("/home/vagrant' lstat("/home/vagrant/foo/bar/baz/0", 0x7fffa350ccf0) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo/bar/baz", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/home/vagrant/foo/bar", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/home/vagrant/foo", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/home/vagrant", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat("/home/vagrant/foo/bar/baz/1", 0x7fffa350ccf0) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo/bar/baz/2", 0x7fffa350ccf0) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo/bar/baz/3", 0x7fffa350ccf0) = -1 ENOENT (No such file or directory) lstat("/home/vagrant/foo/bar/baz/4", 0x7fffa350ccf0) = -1 ENOENT (No such file or directory)