Tag Archives: php
PHP Women at PHP London
At this event I will be busy with phpwomen, wearing my t-shirt and generally making a noise and raising the profile of the group. If you are attending the conference then you are morally obliged to pop over to us and say hello, we like to meet new people. If you are extra nice to us we may give you a t-shirt! There will be women from the UK and also elsewhere in Europe and it’ll be great to meet those I haven’t met yet and also see some old friends from other conferences. An excellent way to spend Leap Year Day in my opinion :)
PHP5 Soap Server
Start Small – Build and Check A Class
I firstly built some unit tests using PHPUnit (more about that another day perhaps, but let me say it is excellent and I tumbled to it really easily once I’d started), then wrote my class and verified the tests were passing. This was to avoid trying to debug the PHP functionality through the added layer of the SOAP.
Simple SOAP Starting Point
My next step was to get a working SOAP service. This isn’t remotely tricky except that PHP can’t generate its own WSDL file (for extremely valid reasons but that doesn’t help me), so you either need to write it by hand or you need to generate it somehow.
As my starting point I took the whole working code from this fantastic example and checked that it worked for me.
SOAP setClass() and WSDL Fiddling
Having got this far I changed my SOAP server code to use the setClass() method and pointed it at my own original class. I then hand-edited the WSDL (one function at a time) to reflect the data types and arguments that would be moving through the service.
The actual service code looks like this:
require_once('lib/myClass.php');
ini_set("soap.wsdl_cache_enabled", "0");
$server = new SoapServer("service.wsdl");
$server->setClass("MyClass");
$server->handle();
The example WSDL supplied by the JimmyZ tutorial has a single function in it at the early stages, and I started with that, then adapted it for one single function from the class. This is perfectly valid providing you don’t try calling anything else! The PHP function declaration took this form:
function getAccountStatus($accountID)
The function returns two variables – it passes back the account ID and also returns information about the number of credits on the account. The accountID is a string of up to 8 characters, the other variable is a number. Here is the WSDL adapted for this purpose:
Once I discovered that WSDLs are best read from end to beginning, I was able to expand the example above for all the other various functions I needed.
Hopefully this helps someone get started. There are various tools available for generating the WSDL, in particular try either George’s suggestion, the offering from phpclasses.org, or check out the automatic generator in ZDE. Certainly there are tools available, but I didn’t manage to find one that did the trick for me.
If you are writing, or have written, a SOAP service in PHP5 then drop a comment and let me know – I certainly felt like I was in a minority on this project. Similarly if I’ve missed anything then I’d appreciate comments so I know for next time.
So Begins a New Chapter
To answer the first three questions: Yes, I am fine. Yes, they are paying me my notice period so I won’t starve. And yes, I need a new job! I’ll put up a coherent post on me and my skills soon.
Donate to PHPWomen and Win
PHPWomen finances goodies to give away at conferences and also assists members who perhaps would not ordinarily be able to attend conferences to get there and participate. More women at conferences …. can that be a bad thing?