Page 1 of 1

Question about PHP files 'required' with fopen_wrappers

Posted: Thu Jan 17, 2008 12:59 pm
by r3gan
I have a question about the require() and include() functions. Here is my example scenario:

Code: Select all

 
    Server A                        Server B
  IP : 1.1.1.1                    IP : 2.2.2.2
    PHP: v 5                        PHP: v 4
 
On Server A, I have a PHP script that require()'s a PHP script on Server B, using HTTP protocol and fopen_wrappers. The script on Server B prints out the IP address using $_SERVER["SERVER_ADDR"]. So, when I run the script on Server A, the script ends but prints out 2.2.2.2 (which is the IP address of Server B)

My question: is it possible to include() or require() a script from a DIFFERENT machine, but have that script run and process on the machine that called it? My desired output from the above example would be 1.1.1.1, rather than 2.2.2.2 I have some third-party PHP libraries I wrote, and I don't want to have to copy them to each and every server where I want to use them. My idea is to just require() them from a stand-alone library server, but they need to run and process as if they were on the local machine that's calling them.

Thanks in advance for any help!

Re: Question about PHP files 'required' with fopen_wrappers

Posted: Thu Jan 17, 2008 1:42 pm
by Jade
I've run scripts from other servers before and at least in my experience, if you include the files/functions you want above the script you run then it shouldn't have a problem running them.

Re: Question about PHP files 'required' with fopen_wrappers

Posted: Thu Jan 17, 2008 2:00 pm
by r3gan
Could you post an example? I just attempted to run a script as you said, but it didn't work. Here's what I did:

Code: Select all

 
<?php
//
// this is testfile.php, the PHP file used in the require() call, it sits on Server B
//
function TestFunction() {
  print "This is the test function!";
}
?>

Code: Select all

 
<?php
//
// this is the PHP file on Server A, which I am running in the browser window
//
require("http://SERVER_B/testfile.php");
 
TestFunction();
?>
When I run the script on Server A, I get "Fatal error: Call to undefined function TestFunction()"

Re: Question about PHP files 'required' with fopen_wrappers

Posted: Thu Jan 17, 2008 2:14 pm
by Jade
One thing I did when I was working with two different servers was made sure they had access to each other. I had to change it so the one server would accept data/database connections from the other. So for instance, if one server is thoroughbred.mydomain.com and the other is dog.mydomain.com I had to add both of those to the localhost of the other server. So dog.mydomain.com got access to thoroughbred.mydomain.com and vice versa. Otherwise the code you have below would work fine for me.