From: Clancy [mailto:clanc...@cybec.com.au]
Sent: 21 August 2009 01:26 PM
Subject: [PHP] Invoking functions stored in a separate directory?
I am developing an idea for a website engine which can be shared between
several different websites. Each website would have its own directory under
a common root directory, and the engine would be in a separate directory
Website_1.com, Website_2.com, Engine
The website directories would each contain the design data for that website,
consisting basically of a mixture of text files and images. The various
pages would be loaded by loading index.php from the website root directory,
and specifying a number of parameters e.g.
I have the minimum amount of code in index.php -- just enough to set some
parameters to identify the website, and then include
../Engine/Main_prog.php. This in turn can include any of a large number of
other include files to carry out particular functions.
I have the prototype working nicely on my PC, and on a stand-alone basis on
a server, but now I am trying to upload the multi-website version to a
public host, and am encountering a number of problems, mainly because I have
never done any serious work with UNIX, and the host support staff don't
understand what I am trying to do.
The problems mainly relate to setting permissions to allow the website to
access the engine code. I only have a rough idea of how the permissions
work, but I think that to include engine code the website has to have read
and execute rights to it, and I also think that so far as the engine is
concerned the website will count as 'other'. (I can easily arrange that all
temporary files are written in the website directory.)
I suspect that rather than including the engine code in index.php, it would
be better to call functions in it, so that the website only required
'execute' rights, but I don't know of any way to do this without having
anything running permanently on the server. Can anyone suggest how it can be
Using include ../Engine/Main_prog.php won't work for you in a production
environment. You need to create a path.php file that defines the absolute
path to the engine for each website, and include it at the top of your
website script. Then you can do something like:
You can have different path files, one for dev and one for live, that allows
you to use the same scripts for both environments and just use the
appropriate path definition script.
E.g. Windows path.php
You shouldn't really have permission problems as long as your website and
engine are on the same server. I do something similar where the bulk of my
code is below doc root, and I use path files to find the main system
directories. The beauty of it is you can change your mind about directory
structures, and just change the path file definitions without making any
changes in the application code (my path file defines about 20 directories).
It also lets you do dev on a Windows pc and deploy on a *nix box without any
problems - just use a different path file for each.
One other advantage it will give you for your particualr design is that you
can have multiple engines per server (e.g. Engine1, Engine2, etc) so that
you can bring one engine down for upgrade while still keeping sites running
on the other engines.
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php