Click here to Skip to main content
11,924,487 members (57,404 online)
Click here to Skip to main content
Add your own
alternative version


25 bookmarked

Creating Web Service Using PHP Within 10 Minutes

, 30 Oct 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Developing web service using PHP within 10 minutes


Today, I am trying to write up on web service functionality and also how to consume it using PHP code. Basically, it is a very beginner level web service tip but you will gather knowledge step by step & easily run it on your server.


  1. What is SOAP?
  2. Why SOAP?
  3. Create web service method
  4. Consume web service


What is SOAP?

SOAP is based on XML so it is considered human read. It is a protocol for accessing a Web Service. It is a simple XML-based protocol to let applications exchange information over HTTP.


In real field, so many applications are required for data communication between systems by Remote Procedure Calls (RPC) between objects like DCOM and CORBA but HTTP was not designed for this.

  • RPC represents compatibility
  • Security problem
  • Firewalls and proxy servers will normally block this kind of traffic.

A better way to communicate between applications is over HTTP as HTTP is supported by all Internet browsers and servers. That's why it is preferable to SOAP Service.

We can collaborate with other programmers building big size and complex applications in multiple platforms.

Using the Code

Here, I will create a web service using PHP code. So let’s follow the steps given below:

Step 1: You will download the library from

Step 2: Run WAMP server, then you will go to www root folder location.

Step 3: Create folder, it’s called “WebServiceSOAP” into www root folder.

Step 4: Paste "lib" folder inside your "www/WebServiceSOAP/" location from Step 1 download files.

Step 5: Create two files “server.php” and “client.php” into WebServiceSOAP folder location.

Step 6: Inside “server.php”, please write the code lines given below:

//call library 
require_once ('lib/nusoap.php'); 
//using soap_server to create server object 
$server = new soap_server; 

//register a function that works on server 

// create the function 
function get_message($your_name) 
return new soap_fault('Client','','Put Your Name!'); 
$result = "Welcome to ".$your_name .". Thanks for Your First Web Service Using PHP with SOAP"; 
return $result; 
// create HTTP listener 

Step 7: After creating “server.php” file, now we will test this server function. Please go to URL & type http://localhost/WebServiceSOAP/server.php?wsdl.

Step 8: Create "client.php" file into WebServiceSOAP folder location. Please find the following code lines:

require_once ('lib/nusoap.php'); 
//Give it value at parameter 
$param = array( 'your_name' => 'Monotosh Roy'); 
//Create object that referer a web services 
$client = new soapclient('http://localhost/WebServiceSOAP/server.php'); 
//Call a function at server and send parameters too 
$response = $client->call('get_message',$param); 
//Process result 
echo "FAULT: <p>Code: (".$client->faultcode."</p>"; 
echo "String: ".$client->faultstring; 
echo $response; 

Step 9: Save all codes, then please go to URL and type http://localhost/WebServiceSOAP/client.php.

Result: Welcome to Monotosh Roy. Thanks for Your First Web Service Using PHP with SOAP

So, today I have shown you how to use simple SOAP web service and to get message from service at client end.

Hope this post will help you to create a simple web service using SOAP. Post your queries if you have any or if there is anything else, please share. Keep visiting for new posts here.
Have a good day!


  • 21st October, 2013: Initial post - Step by step understanding of web service functionality


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Monotosh Roy Mon
Bangladesh Bangladesh
My Name is Monotosh Roy (Mon), Completed Bachelor In Computer Science from West Bengal University of Technology, India & M.Sc. In Computer Science & Engineering from United International University. I have lots of experience on core software development with API service integration more than 8 years using tools- ASP.Net, C#, PL/SQL, WCF, SAP, SugerCRM, Salesforce, VBA Excel Export, Web Service, PHP, and MVC 2/3/4 etc. I had successfully implemented more than 200 projects in boundary as well across boundary followed by project management tools like as Agile, PMP & BCM-

Worked on freelancing marketplace in US & other countries through Odesk, Elance & Freelancer etc

LinkedIn Profile-

You may also be interested in...

Comments and Discussions

GeneralWell Done! thank you - so much. Very clear article.aavr Pin
Member 1138034918-Sep-15 21:54
memberMember 1138034918-Sep-15 21:54 
BugError In this code when i run this code Pin
Member 119644017-Sep-15 1:14
memberMember 119644017-Sep-15 1:14 
GeneralRe: Error In this code when i run this code Pin
John Gunther20-Oct-15 7:08
memberJohn Gunther20-Oct-15 7:08 
BugNot Run Pin
Member 117544029-Jun-15 18:36
memberMember 117544029-Jun-15 18:36 
BugError Pin
Member 117167181-Jun-15 0:46
memberMember 117167181-Jun-15 0:46 
QuestionAssistance writing Web Service for data. Pin
Daniel H Oostra4-May-15 6:28
memberDaniel H Oostra4-May-15 6:28 
QuestionWeb Service Error Pin
Member 1161227316-Apr-15 3:30
memberMember 1161227316-Apr-15 3:30 
BugThis service does not provide WSDL Pin
Member 115719041-Apr-15 1:25
memberMember 115719041-Apr-15 1:25 
Questionserver.php eror Pin
Iqbal Habibie12-Mar-15 16:34
memberIqbal Habibie12-Mar-15 16:34 
AnswerRe: server.php eror Pin
abudulwadoodu19-Apr-15 22:07
memberabudulwadoodu19-Apr-15 22:07 
Question[My vote of 1] down vote Pin
john010128-Feb-15 22:51
memberjohn010128-Feb-15 22:51 
GeneralMy vote of 2 Pin
ke4ktz9-Jan-15 10:15
memberke4ktz9-Jan-15 10:15 
QuestionError Pin
Member 112885215-Dec-14 1:41
memberMember 112885215-Dec-14 1:41 
GeneralThank You Pin
Member 112878124-Dec-14 21:02
memberMember 112878124-Dec-14 21:02 
Questionnot working on xamp Pin
vivekharnal13-Nov-14 21:19
membervivekharnal13-Nov-14 21:19 
AnswerRe: not working on xamp Pin
Member 1175569710-Jun-15 2:18
memberMember 1175569710-Jun-15 2:18 
GeneralMy vote of 1 Pin
arpit goyal13811-Nov-14 20:58
memberarpit goyal13811-Nov-14 20:58 
GeneralRe: My vote of 1 Pin
Iqbal Habibie12-Mar-15 16:36
memberIqbal Habibie12-Mar-15 16:36 
QuestionError Pin
Member 1102096820-Aug-14 20:28
memberMember 1102096820-Aug-14 20:28 
QuestionUncaught SoapFault exception Pin
Member 1100699411-Aug-14 22:25
memberMember 1100699411-Aug-14 22:25 
GeneralMy vote of 1 Pin
CodingLover22-Jul-14 19:51
memberCodingLover22-Jul-14 19:51 
QuestionHow to get XML File ? Pin
Member 105872342-Jul-14 10:45
memberMember 105872342-Jul-14 10:45 
Questioncode changed on nusoap Pin
ali yeganeh6-Jun-14 0:48
memberali yeganeh6-Jun-14 0:48 
Questionim use xampp 1.8.3 and i have one error Pin
phungvanthuy260119884-Jun-14 12:50
memberphungvanthuy260119884-Jun-14 12:50 
GeneralMy vote of 1 Pin
Member 1082418916-May-14 10:49
memberMember 1082418916-May-14 10:49 
QuestionError Pin
Rameshwar Solanki29-Apr-14 0:17
memberRameshwar Solanki29-Apr-14 0:17 
AnswerRe: Error Pin
atrick24-May-14 3:04
memberatrick24-May-14 3:04 
AnswerRe: Error Pin
Member 111250022-Oct-14 0:45
memberMember 111250022-Oct-14 0:45 
QuestionA little modification Pin
DevMostafa24-Mar-14 6:52
memberDevMostafa24-Mar-14 6:52 
Questionservice not provide WSDL Pin
Member 106464855-Mar-14 13:30
memberMember 106464855-Mar-14 13:30 
AnswerRe: service not provide WSDL Pin
Member 111250022-Oct-14 0:42
memberMember 111250022-Oct-14 0:42 
QuestionWSDL PinPopular
amjad farazi26-Feb-14 23:59
memberamjad farazi26-Feb-14 23:59 
i follow all the steps of web services and finally type http://localhost/WebServiceSOAP/server.php?wsdl then i received message on browser
"This service does not provide WSDL"
so how i can solve that problem?
AnswerRe: WSDL Pin
CodingLover22-Jul-14 19:42
memberCodingLover22-Jul-14 19:42 
GeneralRe: WSDL Pin
Member 111250022-Oct-14 0:43
memberMember 111250022-Oct-14 0:43 
QuestionNo answer : white page ! Pin
pierrix2520-Feb-14 9:01
memberpierrix2520-Feb-14 9:01 
QuestionNo answer : white page ! Pin
pierrix258-Feb-14 6:18
memberpierrix258-Feb-14 6:18 
AnswerRe: No answer : white page ! Pin
pierrix2512-Feb-14 12:21
memberpierrix2512-Feb-14 12:21 
QuestionError Pin
nima.sh3-Feb-14 16:59
membernima.sh3-Feb-14 16:59 
AnswerRe: Error Pin
Srihari Sahu12-Feb-14 21:28
memberSrihari Sahu12-Feb-14 21:28 
GeneralThanks for Your PHP service share Pin
ganapathign19-Jan-14 20:19
memberganapathign19-Jan-14 20:19 
QuestionNo result. Error in source code Pin
Sami Ciit8-Jan-14 7:30
memberSami Ciit8-Jan-14 7:30 
AnswerRe: No result. Error in source code Pin
surahman19-May-14 5:47
membersurahman19-May-14 5:47 
Questionerror with soap Pin
Cheick Oumar Fadiga30-Dec-13 17:44
memberCheick Oumar Fadiga30-Dec-13 17:44 
AnswerRe: error with soap Pin
karpdamian9-Jan-14 5:14
memberkarpdamian9-Jan-14 5:14 
QuestionError on Duplicating Tutorial Pin
CMJ-JMC9-Dec-13 6:38
memberCMJ-JMC9-Dec-13 6:38 
Questionthank you Pin
hariprasad14116-Dec-13 19:45
memberhariprasad14116-Dec-13 19:45 
QuestionPassing String from C# to Web Service PHP page Pin
Mudassar Tufail26-Oct-13 7:33
memberMudassar Tufail26-Oct-13 7:33 
Questionsource file cannot be downloaded Pin
fredatcodeproject25-Oct-13 4:02
memberfredatcodeproject25-Oct-13 4:02 
AnswerRe: source file cannot be downloaded Pin
Monotosh Roy Mon25-Oct-13 9:46
memberMonotosh Roy Mon25-Oct-13 9:46 
GeneralRe: source file cannot be downloaded Pin
fredatcodeproject29-Oct-13 23:43
memberfredatcodeproject29-Oct-13 23:43 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151125.3 | Last Updated 30 Oct 2013
Article Copyright 2013 by Monotosh Roy Mon
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid