Page 1 of 1

How do I run an external PHP script using REST or SOAP?

Posted: Sun Mar 29, 2015 10:01 am
by bendy123
I have put together a basic website on Microsoft Azure that is capable of retrieving data from a database and displaying it to the user. However, I need to retrieve the data using an external server and either a REST or SOAP api rather than the website itself. I have created a different Azure website that contains a single PHP script that can retrieve data in the same way that the original website does.

My question is this: How do I use my main website to run the PHP script on the other website using REST or SOAP? Additionally, I need to send a variable to the other website that will tell it which table to retrieve data from. How can I send this variable to the other website using the same REST or SOAP api?

I expect that the working code should look something like the following:

Code: Select all

<?php
    //REST example
    $myTable = "TableOne"; //Database table name
    $url = "www.MyWebsite.azurewebsites.net"; //Server URL
    $script = "RetrieveData.php"; //Server php script

    //I doubt that the proper code will look anything like this, but this is an example
    rest_contact_website($url); //Locate the website
    rest_assign_variable($serverVar, $myTable); //$serverVar refers to the variable in the server script that will have the value of $myTable assigned to it
    rest_run_script($script); //Run the script
    rest_close_connection($url); //Close the connection if necessary
?>

Re: How do I run an external PHP script using REST or SOAP?

Posted: Sun Mar 29, 2015 10:13 am
by Celauran
Retrieving the data should be as simple as sending an HTTP GET request. I'd suggest using Guzzle, though you could use something like cURL if you really wanted to. Depending on the other uses of the website, you may or may not need to set up separate endpoints to be consumed RESTfully. Ideally, you'd be serving up some JSON.