Php 在另一台服务器上调用函数或脚本并接收响应

Php 在另一台服务器上调用函数或脚本并接收响应,php,curl,Php,Curl,我本质上想做的是能够使用PHP在另一台服务器上调用函数或脚本并接收响应。让我举个例子: 在我的web应用程序上,我有一个页面,我需要向服务器发送一些数据,让服务器做一些工作,然后返回一个响应 Web应用程序: <?php // call server script, sending it for example a string, "testString", then wait for a response ?> 服务器脚本: <?php // get the st

我本质上想做的是能够使用PHP在另一台服务器上调用函数或脚本并接收响应。让我举个例子:

在我的web应用程序上,我有一个页面,我需要向服务器发送一些数据,让服务器做一些工作,然后返回一个响应

Web应用程序:

<?php

// call server script, sending it for example a string, "testString", then wait for a response

?>

服务器脚本:

<?php

// get the string "testString", so some work on it and return it, displaying it on the web app

?>

我不是在找人帮我完成这件事,只是为了指引我正确的方向。我已经读过cURL在这方面很有用,但还没有找到适合我的例子,比如:


那么,解决我的问题的理想途径是什么呢?

如果您无法控制这两台机器,或者主机服务器没有为您提供API来实现这一点,那么这是不可行的。否则,只需在主机服务器上设置一些代码即可,这些代码将接收来自
客户端的命令,然后进行相应的处理和响应。设置完成后,您可以轻松地使用
cURL
调用服务器代码,甚至可以使用file
get\u contents

cURL基本上像浏览器一样运行。它向服务器发出HTTP请求并返回响应。因此,一台服务器是“客户机”,一台服务器是“服务器”

在服务器(lol)上,设置一个名为index.php的页面,输出一些文本

<?php

echo 'hello from the server server';

最好的方法是CURL,这样两个独立的服务器就可以互相通信了。我想你们还不知道有什么地方有这样的例子吧?我试过的那些似乎没有任何效果。不过我可以控制这两台机器。
<?php

// init curl object        
$ch = curl_init();

// define options
$optArray = array(
    CURLOPT_URL => 'http://www.serverserver.com',  <--- edit that URL
    CURLOPT_RETURNTRANSFER => true
);

// apply those options
curl_setopt_array($ch, $optArray);

// execute request and get response
$result = curl_exec($ch);

var_dump($result);