On most requests we end up with a getcwd() followed by a chdir() to the
same directory and then a second chdir() to the same directory at the
end of the request:
getcwd("/var/www", 4095) = 14
chdir("/var/www") = 0
... request is processed ...
chdir("/var/www") = 0
which comes from this code in main.c:
if ((primary_file->type == ZEND_HANDLE_FILENAME ||
primary_file->type == ZEND_HANDLE_STREAM) && primary_file->filename) {
VCWD_GETCWD(old_cwd, OLD_CWD_SIZE-1);
VCWD_CHDIR_FILE(primary_file->filename);
}
...
if (old_cwd[0] != '\0') {
VCWD_CHDIR(old_cwd);
}
free_alloca(old_cwd, use_heap);
We probably can't get rid of the second chdir() since we should preserve
our sandbox and leave the process in the same state that we started in
and all sorts of things along the way could theoretically have changed
the cwd. But we should be able to get rid of that first chdir() when
the directory we want to change to is the same as old_cwd.
Perhaps a new macro to not break other code using it?
VCWD_GETCWD_CHDIR_FILE(primary_file->filename, old_cwd, OLD_CWD_SIZE-1)
And have this macro only do the chdir if the directories are different.
-Rasmus
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php