Is there a better way: faking runtime include path

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Is there a better way: faking runtime include path

Post by nielsene »

I need a way to set/specify the include path at runtime based off a portion of the URL. Ie given http://someserver/baseinstalldir/toolna ... /pages.php I need to be able to set a specialized include path based on "instance" where I'll have several instances. Ideally there will only be one copy of all the pages.php (there are about 40 such files). I hate name-mangling (which is why I don't want to use GET style urls which could simplify this).

I've tried several options(listed below) all of them leave me feeling less than thrilled. I'm about to try Option 4, but was wondering if anyone here had any thoughts.

Option 1: store the base include path in a database, parse the url to retrieve it, always use absolute paths.
Pros: not webserver specific
Cons: requires a 2nd database connection per page view (each instance has its own DB, there is a central one for some management purposes, but its seldom connected to. Can be partially lessened by passing the path as a session variable, but you still get the hit on the first page load (which is the most common page hit by several orders of magnitude).

Option 2: make an htaccess file per directory
Pros: little additional server load, may use relative paths
Cons: requires a new file per instance, can't be combined with the last method for reducing the number of copies, requires AllowOverrides Options

Option 3: change hosting services to one that allows delgated dns, use instance.server/baseinstalldir/instance/pages.php, set include path in the vhost directive
Pros: slightly simpler url, little additional server load, single copy of files, may use relative paths
Cons: requires a hosting service that allows delegated DNS

Option 4: use url alias to redirect to the "reference install", the instance name is still in the url, so we can parse that to use.
Pros: low server load, one time change to the apache config
Cons: requires ability to add web aliases, must use absolute paths
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

http://www.php.net/manual/en/function.ini-alter.php

try doing something with that, since it returns the old setting on success, you can just store it in a var and change it back at the end of the script
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Thanks, I hadn't found that function, must have been using bad search terms. I think I'll combine that with option four so I can relative paths and use a single copy of the script files... its the best of several worlds.
Post Reply