Page 1 of 2

Share a variable between two php files on two different serv

Posted: Mon Nov 13, 2006 5:42 am
by Proqrammer
Is there anyway to share a variable lets say an array between two php pages on two different servers?

Posted: Mon Nov 13, 2006 5:51 am
by volka
Can ducks duck? ;)
The answer strongly depends on the actual problem.

Posted: Mon Nov 13, 2006 6:27 am
by Proqrammer
Thanks for your reply Volka,

Let's say I have a php page named "page1.php" hosted on "www.somesite1.com/page1.php"
In this php page I have declared a string variable such as $string1="foo";

Now there is another php page named "page2.php" hosted on another server at "www.somesite2.com/page2.php"
Now is there any built in function or method to have the value of string1 in page2.php ?

Posted: Mon Nov 13, 2006 6:59 am
by volka
Is there a client/browser "between" those two servers, i.e. the browsers request a document from server1 and then from server2 (probably because of something in the doc from server1, a link e.g.)?

Posted: Mon Nov 13, 2006 7:06 am
by Proqrammer
Nope.

Posted: Mon Nov 13, 2006 9:04 am
by volka
Then who or what is when and how invoking the scripts?

Posted: Mon Nov 13, 2006 9:17 am
by m3mn0n
Insert information into database and remotely connect?

Insert information into text file and read from different server?

Secondary server calling on a script directly for results in say XML/tab separated format?

This sort of thing is easily possible, but what you should do is identify whether or not your application is designed optimally because cross-server data exchanges can be costly for script processing time if the application is heavily reliant on this data.

If you feel there is no other way to have the system setup, whatever the system may be, then look into implementing one of the above ways. I'd pick based around what's best for my needs and what's optimal for security and loading times.

By the way, how often is this data updated? Do you want this exchange happening on a schedule in the background or do you want it happening at script run-time when a user is on the site? Can you give an example as to what the data is?

The more information you provide in your problem scenarios the much better it is for the people helping you find a suitable solution, as volka hinted at. ;)

Posted: Mon Nov 13, 2006 9:18 am
by volka
m3mn0n wrote:as volka hinted at. ;)
but only tight-lipped ;)

Posted: Mon Nov 13, 2006 9:48 am
by Proqrammer
The thing is I don't know much about it either, I wanna get employed somewhere and he asked me to solve this issue probably to let me know that I don't know anything about php!

I guess the best way around would be to include a sub in one of the servers is possible.

Posted: Mon Nov 13, 2006 10:00 am
by Proqrammer
I mean, is there any internal way to do it, rather than using a database, or any kind of files?

Posted: Mon Nov 13, 2006 10:06 am
by volka
No, sorry, there's no such magic built-in ;)
If the task really is that unspecific you should ask for clarification. m3mn0n gave you a good starter what might be possible.

Posted: Mon Nov 13, 2006 11:51 am
by Proqrammer
Someone has told me I should use an include file with serialized data! does that make sense?

Posted: Mon Nov 13, 2006 12:00 pm
by Chris Corbyn
Proqrammer wrote:Someone has told me I should use an include file with serialized data! does that make sense?
Yes, but then again not really for just a single value. If it's a scalar value (i.e. a number or a string) then just dump out the value. If it's an array you could of course dump out the serialized string and unserialize() it from the other server.

Look at file_get_contents() but you'll need allow_url_fopen in php.ini for it to work remotely.

http://www.php.net/serialize

Posted: Mon Nov 13, 2006 12:00 pm
by m3mn0n
Do some tests and see if that's suitable.

Posted: Mon Nov 13, 2006 12:33 pm
by RobertGonzalez
You can always pass them as get variables or even post variables. cURL might be able to help also.