情况如下。我的计算机上有一个本地(开发)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?
发布评论
评论(4)
或者您可以使用 cURL。请记住,当您在 PHP 中执行文件时,您应该限制其他人执行此操作的能力(即密码保护页面/目录)并在运行它们之前转义 shell 参数。
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.
您可以使用 PHP cURL 库来查询远程服务器上的脚本。
You can use the PHP cURL library to query scripts on remote servers.
使用 fopen 或 curl 调用远程脚本。
Use fopen or curl to call your remote script.