从不同服务器上的php代码调用php代码

发布于 2024-09-18 02:08:03 字数 310 浏览 4 评论 0 原文

情况如下。我的计算机上有一个本地(开发)PHP 服务器(Win + IIS),我想调用远程服务器上的函数,因为远程服务器(linux)上有一个可执行文件不在我的本地计算机上运行.
因此,远程服务器上将有一个简单的 PHP 页面,它使用给定的参数调用可执行文件并返回结果。
我可以想象从 javascript 向此远程 PHP 页面进行 ajax 调用,但就我而言,我在本地使用 PHPUnit,并且在某一时刻我需要调用此远程页面以获取特定数据(可执行文件提供的数据)。
所以我的问题是 - 如何从 PHP(本地)调用 PHP(远程)? Web 服务是可行的方法还是可以更简单地实现?

The situation is following. I have a local (development) PHP server (Win + IIS) on my computer and I would like to call a function on a remote server because there is an executable file on the remote server (linux) that does not run on my local computer.
So on the remote server would be a simple PHP page which calls the executable with given parameters and returns the results.
I can imagine making an ajax call from javascript to this remote PHP page, but in my case I am using PHPUnit locally and at one point I need to call this remote page for specific data (which the executable file provides).
So my question is - how to make a call from PHP (local) to PHP (remote)? Is web-services the way to go or can this be accomplished simpler?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

小梨窩很甜 2024-09-25 02:08:03
$output = file_get_contents('http://your.remote.server/page.php?args=12345');

或者您可以使用 cURL。请记住,当您在 PHP 中执行文件时,您应该限制其他人执行此操作的能力(即密码保护页面/目录)并在运行它们之前转义 shell 参数。

$output = file_get_contents('http://your.remote.server/page.php?args=12345');

Or you can use cURL. Keep in mind that when you're executing files in PHP you should limit the ability for other people to do so(ie. password protect the page/directory) and escape the shell arguments before running them.

女中豪杰 2024-09-25 02:08:03
$param['one'] = 1;
$param['two'] = 2;
file_get_contents("http://example.com/service.php?".http_build_query($param));
$param['one'] = 1;
$param['two'] = 2;
file_get_contents("http://example.com/service.php?".http_build_query($param));
贩梦商人 2024-09-25 02:08:03

您可以使用 PHP cURL 库来查询远程服务器上的脚本。

You can use the PHP cURL library to query scripts on remote servers.

空城缀染半城烟沙 2024-09-25 02:08:03

使用 fopencurl 调用远程脚本。

Use fopen or curl to call your remote script.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文