Current location: Hot Scripts Forums » Programming Languages » PHP » how to communicate between 2 servers

how to communicate between 2 servers

Reply
  #1 (permalink)  
Old
Newbie Coder
 
Join Date: Aug 2009
Posts: 51
Thanks: 2
Thanked 0 Times in 0 Posts
how to communicate between 2 servers

Hi All,
I want to write 2 php file, each on different servers.
as example: i ll pass two values from php1@server1 to php2@server2, and php2 has to return addition of the number to the server1.
how to do that using http or any way by which i can do this?
Please help.
Reply With Quote

Featured Marketplace Scripts (view more)

  #2 (permalink)  
Old
End User's Avatar
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,029
Thanks: 14
Thanked 35 Times in 33 Posts
You could use cURL on one server to do a POST to a file the other server , which would receive the POST data and then use it as needed. The second file (or another one) could then send a POST response back to a file on the first server.

Quote:
Originally Posted by sunanurag View Post
Hi All,
I want to write 2 php file, each on different servers.
as example: i ll pass two values from php1@server1 to php2@server2, and php2 has to return addition of the number to the server1.
how to do that using http or any way by which i can do this?
Please help.
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | Call Of Duty
Reply With Quote
  #3 (permalink)  
Old
Newbie Coder
 
Join Date: Aug 2009
Posts: 51
Thanks: 2
Thanked 0 Times in 0 Posts
thank u very much i ll try this.....if i ll get any problem i ll again post here plz come again on this post.
Reply With Quote
  #4 (permalink)  
Old
Newbie Coder
 
Join Date: Aug 2009
Posts: 51
Thanks: 2
Thanked 0 Times in 0 Posts
hiii End user,

could you please write a sample script to add two number using curl, which can demonstrate communcation between 2 servers. cause i m getting some problem to understand curl functionality....thanks in advance...
Reply With Quote
  #5 (permalink)  
Old
End User's Avatar
Level II Curmudgeon
 
Join Date: Dec 2004
Posts: 3,029
Thanks: 14
Thanked 35 Times in 33 Posts
Here's an example of how to send POST variables via cURL:

PHP Code:

<?php

 $ch 
curl_init('http://somesite.com/index.php');
 
curl_setopt ($chCURLOPT_POST1);
 
curl_setopt ($chCURLOPT_POSTFIELDS"name=End_User&age=24&city=Seattle");
 
curl_exec ($ch);
 
curl_close ($ch);
?>
__________________
I don't live on the edge, but sometimes I go there to visit.
-------------------------------------------------------------------------
Sanitize Your Data | Oracle Date & Substring Functions | Code Snippet Library | Call Of Duty
Reply With Quote
  #6 (permalink)  
Old
abracadaver's Avatar
Newbie Coder
 
Join Date: Oct 2009
Location: Katy, TX
Posts: 13
Thanks: 0
Thanked 2 Times in 2 Posts
Quote:
Originally Posted by sunanurag View Post
Hi All,
I want to write 2 php file, each on different servers.
as example: i ll pass two values from php1@server1 to php2@server2, and php2 has to return addition of the number to the server1.
how to do that using http or any way by which i can do this?
Please help.
Lots of ways. Here's a simple one since this sounds like homework:

http://server1/php1.php
PHP Code:

$result file_get_contents('http://server2/php2.php?a=1&b=2'); 

http://server2/php2.php
PHP Code:

echo $_GET['a'] + $_GET['b']; 

Reply With Quote
  #7 (permalink)  
Old
carters-site's Avatar
Wannabe Coder
 
Join Date: Sep 2009
Location: Moline, IL
Posts: 100
Thanks: 2
Thanked 1 Time in 1 Post
Just adding another solution

HTTP_Request2

Has docs and examples. Pretty easy to use.
Reply With Quote
  #8 (permalink)  
Old
Newbie Coder
 
Join Date: Aug 2009
Posts: 51
Thanks: 2
Thanked 0 Times in 0 Posts
thanks a lot to all of you...........i ll get back to you ppl...
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Control Panel for Ventilo servers concept Job Offers & Assistance 1 11-25-03 10:32 PM


All times are GMT -5. The time now is 04:37 PM.
vBulletin® Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.