#43864 [Com]: unnecessary lstat64

From: Date: Wed, 16 Jan 2008 17:18:28 +0000
Subject: #43864 [Com]: unnecessary lstat64
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-121342@lists.php.net to get a copy of this message
ID: 43864 Comment by: nlgordon at iastate dot edu Reported By: sq6elt at wp dot pl Status: Open Bug Type: Performance problem Operating System: Linux PHP Version: 5.2.5 New Comment: I've seen this same issue, and while I agree that it is excessive considering the realpath cache. It appears to be a byproduct of using realpath on pretty much all file accesses for includes. Theoretically the realpath cache could be extended to cover directories and the like. I know I would like it, my servers get hit hard because I'm serving php out of AFS space. Previous Comments: ------------------------------------------------------------------------ [2008-01-16 08:21:25] sq6elt at wp dot pl Description: ------------ With a lot of includes, located deep in file system, there may be a performance impact, because of a lot of unnecessary lstats. Why, when there is exactly specified path, any lstats are made. Simple access is sufficient, or I missed something? If some of these are required, then do it only once. I have checked php4, it behaves in the same way. There is no difference, when i use include, include_once, require, require_once. Reproduce code: --------------- Create a directory tree: mkdir -p /tmp/a/b/c/d/e/f/g/h/i/j Two empty php scripts: echo '<? ?>' > /tmp/a/b/c/d/e/f/g/h/i/j/a.php echo '<? ?>' > /tmp/a/b/c/d/e/f/g/h/i/j/b.php and a main script /tmp/t.php <? include "/tmp/a/b/c/d/e/f/g/h/i/j/a.php"; include "/tmp/a/b/c/d/e/f/g/h/i/j/b.php"; ?> Actual result: -------------- Do a strace on t,php strace /usr/bin/php5 t.php 2>&1 | grep lstat64 And guess what: lstat64("/usr", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/usr/bin", {st_mode=S_IFDIR|0755, st_size=49152, ...}) = 0 lstat64("/usr/bin/php5", {st_mode=S_IFREG|0755, st_size=5510176, ...}) = 0 lstat64("/etc", {st_mode=S_IFDIR|0755, st_size=8192, ...}) = 0 lstat64("/etc/php5", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/etc/php5/cli", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/etc/php5/cli/php.ini", {st_mode=S_IFREG|0644, st_size=44278, ...}) = 0 lstat64("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=8192, ...}) = 0 lstat64("/tmp/t.php", {st_mode=S_IFREG|0644, st_size=94, ...}) = 0 lstat64("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=8192, ...}) = 0 lstat64("/tmp/a", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b/c", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b/c/d", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b/c/d/e", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b/c/d/e/f", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b/c/d/e/f/g", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b/c/d/e/f/g/h", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b/c/d/e/f/g/h/i", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b/c/d/e/f/g/h/i/j", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b/c/d/e/f/g/h/i/j/a.php", {st_mode=S_IFREG|0644, st_size=11, ...}) = 0 lstat64("/tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=8192, ...}) = 0 lstat64("/tmp/a", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b/c", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b/c/d", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b/c/d/e", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b/c/d/e/f", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b/c/d/e/f/g", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b/c/d/e/f/g/h", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b/c/d/e/f/g/h/i", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b/c/d/e/f/g/h/i/j", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0 lstat64("/tmp/a/b/c/d/e/f/g/h/i/j/b.php", {st_mode=S_IFREG|0644, st_size=7, ...}) = 0 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43864&edit=1

« previous php.bugs (#121342) next »