views:

64

answers:

6

Hi everybody,

I need a solution to run some PHP code on multiple domains. The domains are hosted on different servers, and the base PHP code isn't on any of them, let's say a dev server.

All I could come up with was using file_get_contents on a file hosted on the dev server, and running that code with eval. So on every domain i have an index.php file with :

error_reporting(0);
$code = file_get_contents("http://www.mydevserver.com/main.php");
if ($code === false) {
// treat error
die();
} else {
// run code
eval($code);
}

So far I have only one file with a few functions in it, but things could get more complex in the near future. And I have to mention I'm not only handling data, but also presentation, so I don't know if an API could help.

Any insights on how I could do this better ?

I have to point out that unfortunately all I have is FTP access on the remote servers and I can't get anything else.

Thank you !

+4  A: 

You should really host the files where-ever they're run in. What you're doing now is very insecure for multiple reasons. If you're concerned about keeping the code in sync, setup subversion, or similar source version control system, then syncing the code between different servers is as simple as updating the local repository.

reko_t
+1  A: 

Options:

  • Store the code locally, keep in sync with either version control checkouts or rsync's.
  • Create an NFS of SSHFS mount (or any mount that's workable), use those files there.
Wrikken
A: 

That file_get_contents will get the return of your PHP script, not the source code.

Please rethink your need to do this and if it really is necessary to load dynamic PHP consider using a secure connection, maybe SFTP.

Also as everyone here suggests, I also recommend using version control for this and only deploying stable versions.

Alin Purcaru
A: 

You can have your source server serve encrypted code that you can decrypt on the "other" servers.

You can also create a proxy script on your source server that serves encrypted, zipped source code which you can decrypt, unzip on the other servers. Both operations are just a few lines of PHP code. You can have your other servers "poll" the master server at regular intervals for updated zip files.

Edit ----

Better go for a SVN (or something similar) server and clients. This takes care of security and code management. You can schedule your servers to perform svn-updates from the source server at regular intervals over HTTPs connection.

Salman A
+1  A: 

Just include or require the damn code (ie. either a script that will spit out the necessary PHP code or a plain text file containing the PHP source code), but I wouldn't recommend doing this (in fact I would urge you to rethink this choice you made). This will only work if URL wrappers are enabled of course.

wimvds
A: 

Come up with a folder structure and file naming scheme that will be consistent on all of these servers. Once you've done that, writing a script to FTP the file to all of the servers at once would be very easy.

Getting and executing code from a remote server is asking to be hacked.

bradym