Before penning ‘How to create web services using PHP’, I would like to give a brief introduction on what web services is all about.
What the term ‘web services’ refers to?
There are several definitions available on the internet about Web Services. In order to make you easily understood, I’ve summarized the definition as shown below:
A web service is any service that:
Is accessible over the internet or intranet networks
Uses standardized XML to encode communications within it
Is Platform independent, meaning not knotted with any OS or programming language
Can incorporate programs, objects, messages, or documents to form information exchange system over the internet
Is self-reliant web based application cited to create products, supply chains or processes over the network
Can be found using a simple search mechanism
Developing Web Services using PHP
Web services are sometimes acknowledged as ‘application services’. All standard PHP based Web Services works use following three elements:
UDDI (Universal Description, Discovery and Integration)
WSDL (Web Services Description Language)
SOAP (Simple Object Access Protocol)
In order to understand the roles and responsibilities of all these components, refer the diagram below. It uses a restaurant’s example to make you understand the concept in the simplest manner.
UDDI is a mechanism that enables clients to dynamically look for other web services. It’s a public directory service where companies can get their web services registered and search for other services as well.
Consider restaurant’s example as shown in figure 1, we can say that defining services is a must. And thus waiter first gives menu to their clients, so as to make them choose the food/dishes they want. You can compare ‘Restaurant Menu’ with ‘WSDL’ file. In WSDL file, you can define the functions and their types you’re going to use.
As you can see from the figure above, SOAP is similar to waiter in a restaurant. Waiter pens your order and delivers it to the kitchen staff (which is server in our case). Similarly, SOAP takes the request from client such that it matches the function definition in WSDL file. And the PHP server returns the result encapsulated in a standardized format as stated in WSDL file.
If you are using the latest version of PHP (PHP 5) on windows, go to your php.ini and uncomment the line extension php_soap.dll, so when you run phpinfo you will find it installed. In case you’re working on Linux OS, you need first install php-soap. And if you’re using PHP 4, you can use NuSOAP to create web services.
Steps to be followed in order to create web services using PHP 5:
Enable SOAP extension in PHP using ‘enable-soap’ command.
In this article, we’ve learned about the fundamental concept of web services, its major components and a standard approach to create a service. Hire PHP Programmer India and thrives on the cutting-edge benefits of web services such as Interoperability, usability, reusability and deployability.