2

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?

2
  • Seeing the phpunit tag I would also recommend to have a stub for this remote data and a config switch to enable/disable use of the stub. Commented Sep 7, 2010 at 20:48
  • Yes, after I wrote this, I also started to think about stub-ing / mocking this out... Commented Sep 8, 2010 at 8:26

4 Answers 4

6
$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.

Sign up to request clarification or add additional context in comments.

Comments

1
$param['one'] = 1;
$param['two'] = 2;
file_get_contents("http://example.com/service.php?".http_build_query($param));

1 Comment

that function is actually http_build_query() - php.net/manual/en/function.http-build-query.php.
0

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

Comments

0

Use fopen or curl to call your remote script.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.