One of the questions that I have is "how long is long?". Here is an interesting example of a large system that I work on.
On the first line of each script, we have a line like: require_once('izfc.core4.php'); //exists in global include path
The job of that script is to find and include all functionality that the application needs at that point, but no more. It traverses the directory tree up one level at a time searching for 4 files in each level. Anything named "_include" is automatically added to the include path, and anything named "_init.php" and "_exec.php" is automatically included (init is top-down, exec is bottom-up). The init and exec files are the directory level control files that include and initialize components of the application. For instance, the database connection is created in a low level _exec.php file.
Performance aside, it has really proved to be a great system for providing directory level functionality (like sessions), database connections, and general functionality includes for a large application (~5000 scripts; 70,000,000 row, 200+ table, 8gb mysql database).
So, this discussion prompted me to take a close look at the performance. By the second line any given script in this section of the project, all of the following files have been found and included (which took 24 file_exist() calls):
Here are the components of the include path that was set:
. /home/ionzoft/z.projects/vos4a/dev.2/virtual/myhealthycustomers.com/_include /home/ionzoft/z.projects/vos4a/dev.2/_include /home/ionzoft/z.projects/vos4a/dev.2//../../izfc/izfc4.production
And here are the files that were included:
[0] => /var/var-home/ionzoft/z.projects/vos4a/dev.2/virtual/_vo/member/menu.php
[1] => /var/var-home/ionzoft/izfc/izfc.core4.php
[2] => /var/var-home/ionzoft/z.projects/vos4a/dev.2/_root.php
[3] => /var/var-home/ionzoft/z.projects/vos4a/dev.2/virtual/myhealthycustomers.com/docroot/_init.php
[4] => /var/var-home/ionzoft/z.projects/vos4a/dev.2/_include/conf.CommunityData.php
[5] => /var/var-home/ionzoft/z.projects/vos4a/dev.2/_exec.php
[6] => /var/var-home/ionzoft/z.projects/vos4a/dev.2/_include/conf.core.php
[7] => /var/var-home/ionzoft/z.projects/vos4a/dev.2/_include/conf.vars.php
[8] => /var/var-home/ionzoft/z.projects/vos4a/dev.2/_include/conf.SysData.php
[9] => /var/var-home/ionzoft/izfc/izfc4.20040124/class.CSysData.php
[10] => /var/var-home/ionzoft/z.projects/vos4a/dev.2/_include/conf.ErrorHandler.php
[11] => /var/var-home/ionzoft/z.projects/vos4a/dev.2/_include/code.ErrorHandler.php
[12] => /var/var-home/ionzoft/z.projects/vos4a/dev.2/_include/conf.db.php
[13] => /var/var-home/ionzoft/izfc/izfc4.20040124/class.CMySQLConnection.php
[14] => /var/var-home/ionzoft/izfc/izfc4.20040124/class.CLog.php
[15] => /var/var-home/ionzoft/z.projects/vos4a/dev.2/virtual/myhealthycustomers.com/docroot/_exec.php
[16] => /var/var-home/ionzoft/izfc/izfc4.20040124/code.Links.php
[17] => /var/var-home/ionzoft/z.projects/vos4a/dev.2/virtual/_vo/_exec.php
[18] => /var/var-home/ionzoft/z.projects/vos4a/dev.2/virtual/_vo/member/_exec.php
[19] => /var/var-home/ionzoft/z.projects/vos4a/dev.2/virtual/myhealthycustomers.com/_include/class.CVOSession.php
[20] => /var/var-home/ionzoft/izfc/izfc4.20040124/class.CSession.php
[21] => /var/var-home/ionzoft/z.projects/vos4a/dev.2/_include/class.CMember.php
[22] => /var/var-home/ionzoft/z.projects/vos4a/dev.2/virtual/myhealthycustomers.com/_include/class.CVOPage.php
[All in all, it is 2108 lines of code that was included; a database connection was established, several queries, session established, configuration arrays loaded, etc...]
Here are some numbers:
- It took .0003 seconds to complete the 24 file_exists() calls
- It took .017 seconds to include the 22 files (2108 lines)
- It took .002 seconds to finish the script, write the output, and get to the bottom.
Obviously, the act of including the files took the longest. How much of that time was filesystem stats, and how much was PHP loading, parsing, and executing the content?
If each file_exists() call uses one or more stats, then I must say that a stat is a very quick operation.
~Jason
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php