Web Services and PHP
NOTE: There was a bug in the SOAP extension prior to version 5.0.2 that prevented signed long values from being passed correctly to and from PHP. As a result, any calls that involved big integers (including the session object's personID) would fail. The long and short of it (no pun intended), you wouldn't be able to do much with Vista web services, because most calls require the session object. The nice PHP volunteers fixed it within 4 days of my reporting it. So, make a mental note to replace all references in this article to PHP 5 with PHP 5.0.2.
For those who haven't heard of it, PHP is a popular, open source scripting language that is especially suited for Web development. PHP commands are embedded in HTML documents and processed each time the pages are requested, much like Microsoft Active Server Pages (ASP) or Java Server Pages (JSP). The language's syntax will be familiar to anyone who has worked with Javascript, Java, C, Basic... you get the picture.
One of the most exciting things about PHP (at least for me) is the wide range of functionality built into it. From database connectivity to regular expressions to FTP to PDF and Flash APIs?, PHP has it all (or almost) and what it doesn't have... well, someone will build it as an extension sooner or later.
For a long time, this was the case for SOAP-based Web Services in PHP. There was a variety of different extensions available and all of them required a bit of tweaking on the server to get them to work.
Enter PHP 5
PHP 5 was released on July 13, 2004 and one of the biggest new features is built-in support for Web Services access using the SOAP protocol. When I found out, I immediately set to work to see how much effort would be required to set it up and create a PHP script to call the Vista Web Services.
It took me about two hours to get it all together, but now that I've done it, I'm hoping others will be able to benefit from my experience and get themselves set up in much less time.
Requirements
- PHP 5
- Apache web server
- Gnome XML Library
I tested PHP 5 with Apache 1.3.12 running on Windows 2000 and the instructions here are specific to Windows 2000, but you can run PHP on several different OS and web server platforms. I will try testing a Linux/Apache setup as well when I get a chance and I'll post my findings here. See the install.txt file included with the PHP distribution for detailed install instructions for your operating system and web server.
NOTE: The nice thing (although many would disagree) about the Windows version of PHP is that SOAP support is already compiled into the binary. If you install on Linux, you will need to compile PHP from source with the --enable-soap option.
Installing PHP 5
Here are the steps I followed for installing PHP 5.
- Download the PHP 5 archive and extract it to a directory on the web server. I extracted it in C:\php. (I'll refer to this as the PHP install directory.)
- In the PHP install directory, make a copy of the php.ini-recommended file and rename it to php.ini.
- Edit php.ini as follows:
- Add this line: extension=php_soap.dll
- Find the line that contains extension_dir= and change it to: extension_dir = "C:\php"
- Move php.ini to the %SYSTEMROOT% directory (on Windows 2000, the default is C:\WINNT).
- Copy the php_soap.dll file from the ext subdirectory to the PHP install directory.
Installing Gnome libxml
Extract libxml2.dll from the Gnome XML library distribution and copy it to the PHP install directory.
Configuring Apache
You also need to modify the Apache configuration file.
- Add the following lines to httpd.conf:
LoadModule php5_module c:/php/php5apache.dll
AddModule mod_php5.c
AddType application/x-httpd-php .php
- Copy php5ts.dll from the PHP install directory into the directory that contains the apache.exe file.
The Moment of Truth
Restart Apache. To see if PHP is installed and working properly, create a file named phpinfo.php in your web server's htdocs directory and add the following code: <?php phpinfo(); ?>
Save the file and open it in a web browser. You should see all kinds of information about your PHP installation. If not, review the install procedure and consult install.txt in your PHP install directory.
If all is well, you can go ahead with something a bit more interesting, like connecting to a WebCT?Vista server and accessing Web Services. Here is a really simple example that uses the Context Web Service to print out the institutions that are available for login:
<?php
$baseUrl = "http:;
$VistaContext = new SoapClient("$baseUrl/Context.wsdl");
$lcs = $VistaContext->getLearningContextList();
$count = count($lcs);
print "There are $count Institutions on this server:<br/>";
print "<table><tr><th>Name</TH><th>GLCID</th></tr>";
foreach($lcs as $lc)
{
print "" . $lc->name . "" . $lc->glcID . "";
}
print "</table>";
?>
Your results should look something like this:
There are 4 Institutions on this server:
Name GLCID
Institution Name 10.0.2.19-1078797443387-2000832000
Dan Institution 10.0.2.19-1078852595711-2001100000
Northern University 10.0.2.19-1080068696268-2200298000
My Institution 10.0.2.19-1084572727374-2560057000
Known Issues
Here are some things that gave me some grief along the way:
Conclusion
With a little perseverance, I managed to get the whole thing up and running in less time than I had expected. (I usually spend a lot of time on trial and error and googling exceptions.) PHP is a great language for server-side scripting and now that SOAP/Web Services support is built in, there's a whole new world of possibilities for developing WebCT? Vista server-side solutions. Personally, I won't be using Java to test new Vista Web Service functionality anymore 
If you've used Vista Web Services with PHP, .Net, Perl, or some other development platform (especially something really exotic!), feel free to contribute an article here on DevNet?. We want to know about it!
 | This article originally authored by Paul Monk on the WebCT DevNet
|
There still seems to be a problem with PHP int types over 2^31. If you pass a SOAP call from PHP to the Blackboard server, PHP converts the int to a float which Java interprets as a Float rather than a Long.
So for example, if you do:
$VistaContext->getRoleIDs($session, $intnum)
where $intnum = 2841304001; I get the following error:
Fatal error: Uncaught SoapFault exception: ns1:SDKSDK0001Invalid parameter(s): one of the mandatory parameters is null or it contains an invalid value (e.g. ID is less than 0) in /web/soap/mysoap.php:22 Stack trace: #0 internal function: SoapClient->__call('getRoleIDs', Array) #1 /web/soap/mysoap.php(22): SoapClient->getRoleIDs(Object(stdClass), -1453663295) #2
If $intnum = 2064677001 (or any other context less than 2^31=2147483648), the call works.
A PHP int is casted to a Java long. PHP converts any number over 2^31 to a float automatically. I've tried to force the casting to an int, but of course that truncates the number.
$intnum = (int)2841304001; //outputs -1453663295
Casting the number to a float or double results in it being converted to a Float rather than a long on the Java side.
A PHP float, double, or real are casted to a Java Float.
(Java casting docs: http://myule.cn:8080/resin-doc/doc/quercus-java-interface.xtp
)
Calls like $VistaContext->getLearningContextIDs($session) do work. Anything you have to pass a number to that has a value over 2^31 fails.
See forum http://forums.edugarage.com/thread.jspa?threadID=323&start=0&tstart=0
for further discussion.