Consider the following:
I have a large project which consists of a parent site, alongside multiple 'child' sites, to which they all share identical 'core / base' content.. (images, 'includes', stylesheets, etc.)
My intent is to have these recurring files reside on 1 particular server, and always reference the same path when in need.
This would result in any modified 'core' files (images, 'includes', stylesheets, etc.) affecting all cross references.
What's the best way to go about at this?
currently, (possibly temporarily) I'm using the following .. <?php readfile('http://remotepath.com/_core/includes/top_nav.php'); ?>
Which is an attempt, at nearest solution to <?php include('/filepath/'); ?>
This brings up an obvious issue - using the following to target current page, will no longer work.. Secondly, is retrieving the content via 'readfile' insecure?
<?php $url = basename($_SERVER['SCRIPT_FILENAME']); echo $url; ?>
this will of course return the path of that file, 'top_nav.php'
How can I get the value of the url / web address using a similar method?
Any insight would be well appreciated! Che开发者_C百科ers.
Don't do this.
It is fine to have your images, scripts and stylesheets on another server. Indeed, this is actually a good thing -- it means you can have more simultaneous file downloads, which will speed up the loading of your site. However, it will be very damaging to do include
calls on remote files. This is because that makes your server do an HTTP request to the remote server. While this takes place (and it could easily take a second or more) your script will do nothing at all. It will slow down your site enormously.
By all means share files between sites. However, I would strongly urge you not to do so as your pages are rendered. You may wish to periodically download files onto the child servers from the parent server and then include them normally from your local file system.
NB The fact that you can call include
or readfile
over HTTP does not mean that you should.
Don't remote include source files. If you want the same copy of a PHP library on a number of different servers, there are a few simple ways to do it. You could cron an rsync that periodically copies any changes from the master to the slaves, or put your shared files into a source code control system like git and then cron a "git pull" command on each slave.
精彩评论