ID: 43864 User updated by: sq6elt at wp dot pl Reported By: sq6elt at wp dot pl Status: Open -Bug Type: Feature/Change Request +Bug Type: Performance problem Operating System: Linux PHP Version: 5.2.5 New Comment:
From: TSRM/tsrm_virtual_cwd.c if (!realpath(path, resolved_path)) { /* Note: Not threadsafe on older BSD's */ if (use_realpath == CWD_REALPATH) { return 1; } goto no_realpath; } use_realpath = CWD_REALPATH; CWD_STATE_COPY(&old_state, state); Manual page says: BUGS Avoid using this function. It is broken by design... So please avoid use this function, as stated above it has significant performance impact and as stated in manual it's simply broken. For now I have disabled this, by undefining HAVE_REALPATH. Previous Comments: ------------------------------------------------------------------------ [2008-01-16 17:18:27] nlgordon at iastate dot edu 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. ------------------------------------------------------------------------ [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