expose php script as web service?

liunx

Guest
I know PHP5 has a cool new Web Services extension for using web services, but what about exposing a PHP script or method as a web service? is there a good online tutorial explaining how to do this?

tia.A "web service" is just a web site like any other - except that it's oriented towards producing content that is to be consumed by a machine rather than by a human.

There is a good online tutorial for explaining how to do this. I'm sure. The Internet is a big place. So big, in fact, that there are machines (<!-- m --><a class="postlink" href="http://www.google.com/search?q=%22web+services+with+PHP%22">http://www.google.com/search?q=%22web+s ... ith+PHP%22</a><!-- m -->) that will help you find stuff in it for you.I should be more specific...

Is there an easy way in php5 to expose a php script as a web service, and handle things like automatic publishing of WSDL documents, emitter tool that automatically creates PHP classes from WSDL documents, converting simple post requests into SOAP-formatted requests, etc.

basically, where is Apache Axis for PHP?

and I've googled (I love that verb) the crap out of this subject and have found that nearly every tutorial out deals with php4 and NuSOAP, or the PEAR SOAP or SOAP_interop, and I'm looking for PHP5-specific examples and tools. hence, the post in PHP5 forum...hoping some other PHP'ers are doing this stuff...pretty cool...from the Zend PHP5 contest...

<!-- m --><a class="postlink" href="http://www.zend.com/php5/contest/contest.php?id=144&single=1I">http://www.zend.com/php5/contest/contes ... &single=1I</a><!-- m --> don't know about the tool you posted but in general it is a very bad idea to use a Webserver (not -service!) based script as WebService.

Take a look into CLI PHP and maybe into sockets if needed. You'll end up having a lot less trouble with ini settings.

All the best of luck,
Sal-it's not a service/daemon that runs to give some functionality to my box. a Web Service.

<!-- m --><a class="postlink" href="http://www.webopedia.com/TERM/W/Web_services.htmlWell">http://www.webopedia.com/TERM/W/Web_services.htmlWell</a><!-- m -->, I don't know about you but to me anything that listens to a port or socket and can be queried to perform one task or another is a daemon.

A WebService is no difference.

You'll realize what I mean when your Apache-based WebService will be the subject to DoS for the first time. Not a real attack of course, no one would bother to do that.

Maybe it will be a glitch in the server script itself, in the requesting client, a malformed request maybe or a high server-load at the time of the request. You name it.

At sometime something will happen that will cause a problem. If you run that on Apache (or any other webserver), your site itself might get inaccessible, memory might leak and other things.

Even if you manage to do the stunt to create the first fault-free piece of code in the world, every single connection to your WebService will bind a Apache child-process to it, taking up several megabytes in RAM, spamming your harddisk with useless logging entries and denying that very Apache child-process to more relevant tasks, namely serving HTML.

Create a 5-line script that will spawn an endless amount of SOAP clients or perform time-consuming queries, connecting to your Apache-based WebService and Port 80 de facto will go offline. The list is endless.

But form the impression you give me, you prefer to find all that out the hard way.

Good luck then,
Sal-I actually prefer to learn how to expose a php class/method as a web service. a PHP web service should perform technically the same as a php web page. the only difference is that instead of serving up HTML in response to HTTP requests, it serves up SOAP (XML) responses to SOAP requests.

your points about a web service and the security/stability-type implications are true, but are also true for any php page that is publicly accessible via Apache - something I'll have to worry about regardless.

if you can't contribute to the topic that the post is about, do you automatically assume the the topic is debunk? it's plenty useful for developers to be able to expose PHP code as web services...I want to find out how to do it. if you don't think it will be useful, or you think it will be a horrible server mess, that's fine. but you're not contributing to the discussion at hand.Of course, if it's a program waiting for and responding to HTTP requests with HTTP responses, that's pretty much the definition of a web server....Saloon spouts nonsense. There's nothing wrong with using Apache as an application server platform. It's common.

There's nothing mysterious about a Web service; it's just an interprocess communication mechanism that uses the HTTP request/response model. All else (SOAP, WDSL, et cetera) is implementation detail.

See <!-- m --><a class="postlink" href="http://pear.php.net/packages.php?catpid=23&catname=Web%20Services">http://pear.php.net/packages.php?catpid ... 20Services</a><!-- m --> for some resources.thanks Yelvington...

I've seen most of those and they're very useful. I think I'd be wanting to work with the most generic one, the SOAP package, and I seem to remember development on that package has trailed off.

I'm actually finding most of the great resources from Zend, (duh!) and they have great example cases for the new SOAP Extension in php5 (<!-- m --><a class="postlink" href="http://www.zend.com/php5/articles/php5-SOAP.php">http://www.zend.com/php5/articles/php5-SOAP.php</a><!-- m -->) .The tutorials you find probably tell you that you have to write your own WSDL for your service. Thats the missing piece to php5. The lack of automatic wsdl generation.

I created a (windows only) program to generate a wsdl for a php web service. Its pretty basic right now.. did it in a day.. but it works for basic services.

<!-- m --><a class="postlink" href="http://monkeytroy.com/software/phpwsdlgen/phpwsdlgen.php">http://monkeytroy.com/software/phpwsdlg ... sdlgen.php</a><!-- m -->

Hope this will help someone like me who needed basic wsdl written for their service.Someone has suggested to use PEAR::SOAP first to get the WSDL file then use it with SOAP extension. Maybe this way work.
 
Back
Top