PHP

PHP and Web Service
PHP is a widely-used general purpose scripting language that is specially designed to work on the Web and very well suited for web development. Although it is possible to develop Web Services in PHP we will focus on the consumption of the Web Services using PHP language.

In the following section we will provide code snipets and full listings of PHP code that can be used to consume SOAP based web services.

Requirements

 * We assume that reader is familiar with the PHP language and has it installed.
 * We will be using NuSOAP Toolkit for our PHP-SOAP interactions.
 * All our test code was developed on Windows 2003, so we use default PHP settings for Windows-IIS6 environment.

Installing NuSOAP
You can install NuSOAP pretty much anywhere you want as long as PHP system can find it. In our case we have include_path variable in php.ini set to and NuSOAP installed in the C:\PHP\Includes\NuSOAP folder.

Consuming Web Service
NOTE: We will be using CDYNE's Phone Notify! for all our examples.

In order to consume a webservice from PHP using NuSOAP you have to do 3 main steps:

Step 1 Create an instance of the soapclient class: Step 2 Create parameters array for a method that you want to use, we will be using NotifyPhoneEnglishBasic which has 3 parameters: Step 3 Invoke the method:

NotifyPhoneEnglishBasic
Here is the test form that we used for NotifyPhoneEnglishBasic form1.php: NotifyPhoneEnglishBasic.php looks like this:

Interpreting result of the Notify methods
All Notify methods ( NotifyPhoneAdvanced, NotifyPhoneBasic, NotifyPhoneBasicWithTransfer, NotifyPhoneBasicWithTryCount, NotifyPhoneEnglishBasic ) return a result structure. That structure is slightly different depending on the method you call, but it has some common fileds. For example this is what is returned for NotifyPhoneEnglishBasic: Array (    [NotifyPhoneEnglishBasicResult] => Array         ( [ResponseCode] => 0 [ResponseText] => Queued [CallAnswered] => false [QueueID] => 12778 [TryCount] => 0 [Demo] => true [Duration] => 0 [StartTime] => 0001-01-01T00:00:00 [EndTime] => 0001-01-01T00:00:00 [MinuteRate] => 0 ) )

We are interested in QueueID field. That field is one of the fields that present in the result structure for all Notify methods. QueueID is a unique identifier of the call that you have made with the one of the Notify methods. All Notify methods are asynchronous methods meaning they return right away even if the call is still in progress. In order to obtain the current status of the call you can use GetQueueIDStatus method using the QueueID value from the result of the Notify call:

GetQueueIDStatus returns another structure:

Array (   [GetQueueIDStatusResult] => Array        ( [ResponseCode] => 0 [ResponseText] => Queued [CallAnswered] => false [QueueID] => 12846 [TryCount] => 1 [Demo] => false [MachineDetection] => UNKNOWN [Duration] => 0 [StartTime] => 2006-08-10T19:27:32.378Z [EndTime] => 0001-01-01T00:00:00 [MinuteRate] => 0 ) )

Because of the asynchronous nature of the Notify methods you will need to call GetQueueIDStatus several times if you want to get confirmation of the call completion and all information associated with the completed call.

UploadSoundFile
Test form form2.php: UploadSoundFile.php:

Conclusion
As you can see PHP language has excellent toolbox that allows you to use Web Services. Please feel free to add your comments and question on the Talk page.

CDYNE Team.