SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast konky2000's Avatar
    Join Date
    Mar 2003
    Location
    Oakland
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    setting global include paths

    I was looking at phpmvc.net and noticed that they do the following:

    PHP Code:
         function getGlobalPaths() {
     
             
    // Setup the main phpmvc application include() directories here
             // Note: could be placed in a n xml config file later !!
             
    $appDirs = array();
             
    $appDirs[] = ''// application root directory
             
    $appDirs[] = 'WEB-INF';
             
    $appDirs[] = 'WEB-INF/lib/collections';
             
    $appDirs[] = 'WEB-INF/lib/database';
             
    // ... there are about a dozen lines like this
             
    $appDirs[] = 'WEB-INF/classes/phpmvc/upload';
             
    $appDirs[] = 'WEB-INF/classes/phpmvc/utils';
             return 
    $appDirs;
     
         } 
    They have a couple of other methods that create further directory names which are all added together into a long list of directory names called $cPath that are then fed to the following:

    PHP Code:
     ini_set('include_path'$cPath); 
    The result is that 'include_path' has a couple dozen paths in it, and any time a file is included one only needs to refer to the filename in any include like:

    PHP Code:
     include 'PressRelase.php'
    My initial gut feeling is that this is a bad idea. It seems like a potential performance problem if every single time I include a file, PHP is going to have to search through all those directories until it find the file I'm looking for.

    What I do is set constants like TEMPLATES, CLASSES and then when I need to include a TEMPLATES, I go

    PHP Code:
     include TEMPLATES.'PressRelease.php'
    Are things like php.mvc's setup common? Is it a performance hit to fill 'include_files' with so many paths?
    Konky 2000 Collections - Japanese stickers and floaty pens

  2. #2
    Massimiliano Bruno Giordano sid egg's Avatar
    Join Date
    Aug 2004
    Location
    Canada
    Posts
    1,280
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by konky2000
    ....

    PHP Code:
     ini_set('include_path'$cPath); 
    The result is that 'include_path' has a couple dozen paths in it, and any time a file is included one only needs to refer to the filename in any include like:

    PHP Code:
     include 'PressRelase.php'
    My initial gut feeling is that this is a bad idea. It seems like a potential performance problem if every single time I include a file, PHP is going to have to search through all those directories until it find the file I'm looking for.

    What I do is set constants like TEMPLATES, CLASSES and then when I need to include a TEMPLATES, I go

    PHP Code:
     include TEMPLATES.'PressRelease.php'
    Are things like php.mvc's setup common? Is it a performance hit to fill 'include_files' with so many paths?
    It's definately slow to use include_path, however, I do this, I find it works best on a cPanel server that you have reseller/whm on. I have 2 servers, one is shared [and i have a reseller], one is dedicated

    On the reseller one, I have an account called global, and, I include all my stuff through it. include("/home/global/class/asdf.php");

    On the dedicated one, I do the same thing, but use /usr/phpdev/classes/

    However! Neither of these are transferable solutions, if you plan on distributing your projects I find the define() method works the best (your include TEMPLATES."/file";

    My initial gut feeling is that this is a bad idea. It seems like a potential performance problem if every single time I include a file, PHP is going to have to search through all those directories until it find the file I'm looking for.
    It also really hurts your global namespace for files :-)
    GamesLib.com - the slickest, most complete and
    easily navigatible flash games site on the web.

  3. #3
    If it aint Dutch it aint much Kilroy's Avatar
    Join Date
    Oct 2003
    Location
    The Netherlands
    Posts
    406
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I use an object with public variables, which get assigned from a config.php file. Using them goes as follows:
    PHP Code:
    require_once $config->site_path '/lib/class_blah.php'
    This config object can then be passed on to other object, which gets rid of the use of globals. I also did not like the idea of making constants of all these variables, but it might be faster. I'll look into it sometime.

  4. #4
    SitePoint Addict
    Join Date
    Apr 2004
    Location
    Melbourne
    Posts
    362
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We use something similar in prado (using('path.to.class.folder') which adds the path/to/class/folder directory to the include path, which is then hit by __autoload. This way only folders that are actually going to be used are added to the classpath instead of having to have it predefined somewhere. There is something of a performance hit, but the ease of just having your classpath instead of worrying about including() files is better.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •