Using Amazon Web Services With PHP And SOAP (part 1) - Remote Control (
Page 2 of 9 )
Before we get into the code, though,
you need to have a clear understanding of how Amazon Web Services, aka AWS,
works. This involves getting up close and personal with a complicated little
critter known as SOAP, the Simple Object Access Protocol.
According to
the primer available on the W3C's site (
http://www.w3.org/2002/ws/), SOAP is a
"lightweight protocol for exchange of information in a decentralized,
distributed environment. It is an XML based protocol at the core of which is an
envelope that defines a framework for describing what is in a message and how to
process it and a transport binding framework for exchanging messages using an
underlying protocol."
If you're anything like me, that probably made
very little sense to you. So here's the Reader's Digest version, which is far
more cogent: "SOAP is a simple XML based protocol to let applications exchange
information over HTTP." (
http://www.w3schools.com/soap/soap_intro.asp)
SOAP
is a client-server paradigm which builds on existing Internet technologies to
simplify the task of invoking procedures and accessing objects across a network.
It uses XML to encode procedure invocations (and decode procedure responses)
into a package suitable for transmission across a network, and HTTP to actually
perform the transmission.
At one end of the connection, a SOAP server
receives SOAP requests containing procedure calls, decodes them, invokes the
function and packages the response into a SOAP packet suitable for
retransmission back to the requesting client. The client can then decode the
response and use the results of the procedure invocation in whatever manner it
chooses. The entire process is fairly streamlined and, because of its reliance
on existing standards, relatively easy to understand and use.
Here's a
quick example of what a SOAP request for the procedure getFlavourOfTheDay()
might look like:
<?xml version="1.0" ?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:si="http://soapinterop.org/xsd" xmlns:ns6="http://testuri.org"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns6:getFlavourOfTheDay>
<day xsi:type="xsd:string">monday</day>
</ns6:getFlavourOfTheDay>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
And here's what the response might look like:
<?xml version="1.0" ?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:si="http://soapinterop.org/xsd" xmlns:ns6="http://testuri.org"
SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns6:getFlavourOfTheDayResponse>
<flavour xsi:type="xsd:string">pineapple</flavour>
</ns6:getFlavourOfTheDayResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
I'm not going to get into the details of how SOAP works in
this article, preferring instead to focus on how SOAP can be exploited in the
context of PHP and AWS. If you're new to SOAP, the information above should be
sufficient to explain the basic concepts and ensure that you can follow the
material that comes next; however, if you're interested in learning more about
SOAP (or if you just have trouble falling asleep at night), you should read the
W3C's specifications on the protocol - links will be included at the end of this
article.