June 29, 2012 6:37 am

Create a web service with PHP

Web Service are typical Application Programming Interface (API) or Web APIs can accessed via Hypertext Transfer Protocol (HTTP) with an XML serialization in conjunction with other Web-related standards.

This Article show you how to create a simple Web Service.

Soap Server

SimpleServer.php

Soap Client allows you to communicate with server

SimpleClient.php

Soap View to interact for end-user

SimpleView.php

Author Huzoor Bux

I am Huzoor Bux from Karachi (Pakistan). I have been working as a PHP Developer from last 5+ years, and its my passion to learn new things and implement them as a practice. Basically I am a PHP developer but now days exploring more in HTML5, CSS and jQuery libraries.


Tutorial Categories:
  • Margono

    i try to use code above,
    but i have error as “looks like we got no XML document”
    how to solve it ?
    thank you

  • thiyagu

    i tried this but am not getting any result

    • huzoorbux

      any error? please post here.

      • trocatout

        I tried this too but i’ve any result too… Could you explain much more how to configure the different apache server ?
        By reading the code i ‘dont unerstand when the soap server is running ?

        I see that the location of the simple client invoke “HelloServer.php” : it’s a mistake ? the web service file name is “SimpleServer.php”. I’m right ?

        Thank you for yours answers.

  • elecguy

    I tried this also as I was looking for a very simple example implementation to try to understand some errors I was getting with a more complex implementation. What a surprise when it came up with the same error that my complex implementation was having.

    FWIW: The SimpleClient throws a SoapFault error that is announced as “Client: “DTD are not supported by SOAP”. I understand that this is the error when the SoapClient gets returned a regular HTML file, not a Soap message.
    I am testing it with localhost, just like the example provided.
    Any ideas on this?

    FWIW: The correction suggested by trocatout is correct.

    • trocatout

      I tried again and the client has no results and stop after excedeed time. I tried with and without nusoap lib :

      “Fatal error: Maximum execution time of 30 seconds exceeded in C:wampwwwhelloSimpleClient.php on line 19”

      Could you explain me ?

      Thank you !

    • huzoorbux

      Download the code and change the uri parameter in SimpleClient.php file.

      $client = new SoapClient(null, array(

      'location' => "http://Your_Domain/Web_Service/SimpleServer.php",

      'uri' => "http://Your_Domain/Web_Service/"));

  • hira ba

    hira ba

    I tried this also as I was looking for a very simple example implementation to try to understand some errors I was getting with a more complex implementation. What a surprise when it came up with the same error that my complex implementation was having.

  • hira ba

    nhgjghjghjg

  • hira ba

    FWIW: The SimpleClient throws a SoapFault error that is announced as “Client: “DTD are not supported by SOAP”. I understand that this is the error when the SoapClient gets returned a regular HTML file, not a Soap message.

  • hira ba

    Could you explain me ?

    Thank you !

  • uff… thank you so much ..you saved me…. Thanks, Thanks, Thanks, Thanks…..

  • Pranav

    Can u explain a login in php using web services

  • Javaid

    This topic has really helped me out. Very simple tutorial on webservice for the begineers.

  • Max John

    Hello Please can you do your script in the procedural way and then in the class manner. Some of us have only mastered the procedural way and all those who know classes know procedural (functions).
    Thanks

    • Thanks for your suggestion we will follow for our upcoming tutorials

      • Max John

        Tks a lot. And please can u do a script on how to upload the content of a csv file to a form which will enable you to choose where each field should be inserted ?

        • working on it and hopefully make something soon

          • Max John

            I think I am in love with PhpGang Lol

    • Thanks for your suggestion we will follow for our upcoming tutorials

  • Benny

    Hi guys, I urgently need help.
    For years we program in php but recently I approached the world of the web service, and I have some difficulties to understand them … I hope I can help.
    First I tried to copy and paste the script proposed on my server but does not want to work, but if I use external service wsdl everything works correctly …. Is not there need some special configuration of the server to act as ” server-side “?

    Also with a bit of effort I managed to make simple webservice, but now I find myself to have a particular need …. An external I send a file (xml) in parts base_64 and I should read it and save it on the server a single file decrypted.
    How do I get the files? Can I read them as if it were a $ _files?

    And if dovvessi find me in the situation of having to send a xml file (thus act as a server) as I do?

    I hope you can help me with examples of why I’m really in trouble.

    Thanks so much

  • Shaan Ansari

    need to integrate bluedart api using webservices bhaijaan need your help integration on core php

  • Manvi Agarwal

    How to pass multiple parameter and using username and password.

  • Manvi Agarwal

    How to pass multiple parameter and using username and password.

  • Ravi Dangar

    how to update table using php web services in mysql