<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>A K Chauhan's Blog &#187; Web Service</title>
	<atom:link href="http://www.akchauhan.com/category/web-service/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.akchauhan.com</link>
	<description>PHP, MySql, JavaScript, JQuery, Prototype, Drupal, HTML, CSS and more...</description>
	<lastBuildDate>Mon, 02 Jan 2012 03:29:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Create a TinyURL using PHP and TinyURL API</title>
		<link>http://www.akchauhan.com/create-a-tinyurl-using-php-and-tinyurl-api/</link>
		<comments>http://www.akchauhan.com/create-a-tinyurl-using-php-and-tinyurl-api/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 07:30:18 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Service]]></category>
		<category><![CDATA[TinyUrl]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=591</guid>
		<description><![CDATA[TinyURL is an awesome service. For those who don&#8217;t know what TinyURL is, TinyURL allows you to convert your long URLs like &#8220;http://www.akchauhan.com/category/jquery/&#8221; to small URLs like &#8220;http://tinyurl.com/yz4c4ba&#8221;. Basically you need such type of service when you are posting your data to some third party web service and there is limit on the number of [...]]]></description>
			<content:encoded><![CDATA[<p><strong>TinyURL </strong>is an awesome service. For those who don&#8217;t know what <strong>TinyURL </strong>is, <strong>TinyURL </strong>allows you to convert your long URLs like <strong>&#8220;http://www.akchauhan.com/category/jquery/&#8221;</strong> to small URLs like <strong>&#8220;http://tinyurl.com/yz4c4ba&#8221;</strong>. Basically you need such type of service when you are posting your data to some third party web service and there is limit on the number of characters you can post like <strong>Twitter</strong>. Twitter only allow 140 characters long Tweet.</p>
<p>Using the PHP and TinyURL API, you can create these tiny URLs.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_tiny_url<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span>  
<span style="color: #009900;">&#123;</span>  
	<span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
	<span style="color: #000088;">$timeout</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">;</span>  
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span>CURLOPT_URL<span style="color: #339933;">,</span><span style="color: #0000ff;">'http://tinyurl.com/api-create.php?url='</span><span style="color: #339933;">.</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span>CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
	<span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span>CURLOPT_CONNECTTIMEOUT<span style="color: #339933;">,</span><span style="color: #000088;">$timeout</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
	<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
	<span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>  
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//test it out!</span>
<span style="color: #000088;">$new_url</span> <span style="color: #339933;">=</span> get_tiny_url<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://www.akchauhan.com/category/jquery/'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//returns http://tinyurl.com/yz4c4ba</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$new_url</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/create-a-tinyurl-using-php-and-tinyurl-api/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Create Windows Service to Schedule PHP Script execution</title>
		<link>http://www.akchauhan.com/create-windows-service-to-schedule-php-script-execution/</link>
		<comments>http://www.akchauhan.com/create-windows-service-to-schedule-php-script-execution/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 15:02:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Web Service]]></category>
		<category><![CDATA[Job Schedule]]></category>
		<category><![CDATA[Windows Service]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=560</guid>
		<description><![CDATA[If you want to schedule your PHP script or any other command on Windows Platform recursively after a fix interval of time then you can create a Windows Service for it. Windows service is very easy to create in Visual Studio.Net. I&#8217;m using C# language for this scheduler service you can also use VB.net for [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to schedule your PHP script or any other command on <strong>Windows Platform</strong> recursively after a fix interval of time then you can create a <strong>Windows Service</strong> for it. Windows service is very easy to create in Visual Studio.Net. I&#8217;m using <strong>C#</strong> language for this scheduler service you can also use <strong>VB.net</strong> for it. Basically we need this type of service if we want to execute some PHP script in background in a specific interval of time. For example, If you want to import data in bulk from some web service.</p>
<p>You need to follow these steps: -</p>
<ul>
<li>
Create a project by using the Windows Service application template. This template creates a class for you that inherits from ServiceBase and writes much of the basic service code, such as the code to start the service.</li>
<li>
Write the code for the OnStart and OnStop procedures, and override any other methods that you want to redefine.
</li>
<li>
Add the necessary installers for your service application. By default, a class that contains two or more installers is added to your application when you click the Add Installer link: one to install the process, and one for each associated service that your project contains.
</li>
<li>
Build your project.
</li>
<li>
Create a setup project to install your service, and then install it.
</li>
<li>
Access the Windows 2000 Services Control Manager and start your service.
</li>
</ul>
<p>For more detail check &#8220;<strong>Walkthrough: Creating a Windows Service Application in the Component Designer</strong>&#8221; topic in <strong>MSDN</strong>.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">using <span style="color: #990000;">System</span><span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Collections<span style="color: #339933;">.</span>Generic<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>ComponentModel<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Data<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Diagnostics<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Linq<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>ServiceProcess<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Text<span style="color: #339933;">;</span>
using <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Timers<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">namespace</span> MyNewService
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">public</span> partial <span style="color: #000000; font-weight: bold;">class</span> MyNewService <span style="color: #339933;">:</span> ServiceBase
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">private</span> Timer syncTimer <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>  
&nbsp;
        <span style="color: #000000; font-weight: bold;">public</span> MyNewService<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            InitializeComponent<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">protected</span> override void OnStart<span style="color: #009900;">&#40;</span>string<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            syncTimer <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Timer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            this<span style="color: #339933;">.</span>syncTimer<span style="color: #339933;">.</span>Interval <span style="color: #339933;">=</span> <span style="color: #cc66cc;">180000</span><span style="color: #339933;">;</span>
            this<span style="color: #339933;">.</span>syncTimer<span style="color: #339933;">.</span>Elapsed <span style="color: #339933;">+=</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Timers<span style="color: #339933;">.</span>ElapsedEventHandler<span style="color: #009900;">&#40;</span>this<span style="color: #339933;">.</span>syncTimer_Tick<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            syncTimer<span style="color: #339933;">.</span>Enabled <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">protected</span> override void OnStop<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            syncTimer<span style="color: #339933;">.</span>Enabled <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">private</span> void syncTimer_Tick<span style="color: #009900;">&#40;</span>object sender<span style="color: #339933;">,</span> EventArgs e<span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
            <span style="color: #990000;">System</span><span style="color: #339933;">.</span>Diagnostics<span style="color: #339933;">.</span>Process<span style="color: #339933;">.</span>Start<span style="color: #009900;">&#40;</span><span style="color: #339933;">@</span><span style="color: #0000ff;">&quot;C:<span style="color: #660099; font-weight: bold;">\xa</span>mpp\htdocs<span style="color: #000099; font-weight: bold;">\t</span>ask.bat&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>  
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The <strong>task.bat</strong> file is a batch file. We are executing our PHP script through this batch file. First we set the path of directory where php.exe is located in your windows. The <strong>import.php</strong> is basically importing data in bulk from some web and we need to execute this script file background in every 3 minutes.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">@</span><span style="color: #b1b100;">echo</span> off
cd\
set path<span style="color: #339933;">=</span>C<span style="color: #339933;">:</span>\xampp\php<span style="color: #339933;">;</span>
cd <span style="color: #0000ff;">&quot;C:<span style="color: #660099; font-weight: bold;">\xa</span>mpp\htdocs&quot;</span>
php import<span style="color: #339933;">.</span>php
<span style="color: #990000;">exit</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/create-windows-service-to-schedule-php-script-execution/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Create Web Services using AMFPHP and XML-RPC</title>
		<link>http://www.akchauhan.com/create-web-services-using-amfphp-and-xml-rpc/</link>
		<comments>http://www.akchauhan.com/create-web-services-using-amfphp-and-xml-rpc/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 14:23:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Web Service]]></category>
		<category><![CDATA[AMFPHP]]></category>
		<category><![CDATA[XMLRPC]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=485</guid>
		<description><![CDATA[Here I&#8217;m going to demonstrate how we can create web services using AMFPHP and access them using XML-RPC. First, let&#8217;s understand some important terms:- AMFPHP: AMFPHP is a free open-source PHP implementation of the Action Message Format(AMF). AMF allows for binary serialization of Action Script (AS2, AS3) native types and objects to be sent to [...]]]></description>
			<content:encoded><![CDATA[<p>Here I&#8217;m going to demonstrate how we can create web services using AMFPHP and access them using XML-RPC. First, let&#8217;s understand some important terms:-</br></p>
<p><strong>AMFPHP: </strong> AMFPHP is a free open-source PHP implementation of the Action Message Format(AMF). AMF allows for binary serialization of Action Script (AS2, AS3) native types and objects to be sent to server side services. You can learn more about AMFPHP from its official website <a href="http://www.amfphp.org">www.amfphp.org</a>.</br></br></p>
<p><strong>XML-RPC: </strong>It&#8217;s a specification and a set of implementations that allow software running on disparate operating systems, running in different environments to make procedure calls over the Internet. You can learn more about AMFPHP from its official website <a href="http://www.xmlrpc.com/">www.xmlrpc.com</a>.</br></br></p>
<p>So, here we are creating web services for FLEX or FLASH which we can directly call using the XML-RPC because AMFPHP already included the batteries for XML-RPC and JSON. We don&#8217;t need to do any thing special for accessing same services using XML-RPC.</br></br></p>
<p>First, we need to download AMFPHP. You can download the latest version of from <a href="http://sourceforge.net/projects/amfphp/files/#files">here</a>.</br> Unzip the files and place them into your htdocs directory. You can visit <strong>http://localhost/amfphp/gateway.php</strong> URL in your local to check the AMFPHP is properly installed or not.</p>
<p><strong>1. How to create web service using AMFPHP</strong><br />
In AMFPHP, all files related to web services should be places inside <strong>&#8220;amfphp\services&#8221;</strong> directory. I&#8217;m considering here an example of &#8220;Order&#8221; Web Service to make understand it easily.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * This class provide methods for handling orders received through web
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> WebOrders <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">function</span> _getStoreInfo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$storeid</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$query_id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;SELECT * FROM store WHERE storeid = '<span style="color: #006699; font-weight: bold;">$storeid</span>' AND status = 1&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">mysql_num_rows</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query_id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_fetch_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
     * Method to receive new order from web.
     * @returns order request id. In case of error return error message.
     */</span>
    <span style="color: #000000; font-weight: bold;">function</span> receiveNewOrder<span style="color: #009900;">&#40;</span><span style="color: #000088;">$order</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$store_info</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_getStoreInfo<span style="color: #009900;">&#40;</span><span style="color: #000088;">$order</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'storeid'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$store_info</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">return</span> <span style="color: #0000ff;">'Invalid store ID.'</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;SELECT MAX(fld_order_id) AS fld_order_id FROM tbl_order&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$query_id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$obj</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_fetch_object</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query_id</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #000088;">$next_fld_order_id</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_null</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fld_order_id</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$next_fld_order_id</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$obj</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">fld_order_id</span> <span style="color: #339933;">+</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
                <span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO tbl_order(fld_order_id, fld_total, fld_tax, fld_customer_name, fld_phone, fld_address, 
				fld_email_id, fld_del_status, fld_comment_cust, fld_order_status, fld_request_time, fld_lastupdated)
				VALUES('<span style="color: #006699; font-weight: bold;">$next_fld_order_id</span>', '<span style="color: #006699; font-weight: bold;">{$order['total']}</span>', '<span style="color: #006699; font-weight: bold;">{$order['tax']}</span>', '<span style="color: #006699; font-weight: bold;">{$order['customer_name']}</span>', '<span style="color: #006699; font-weight: bold;">{$order['phone']}</span>', 
				'<span style="color: #006699; font-weight: bold;">{$order['address']}</span>', '<span style="color: #006699; font-weight: bold;">{$order['email']}</span>', '<span style="color: #006699; font-weight: bold;">{$order['delivery']}</span>', '<span style="color: #006699; font-weight: bold;">{$order['note']}</span>', '1', NOW(), NOW())&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$query_id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$order</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'products'</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$product</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$sql</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;INSERT INTO tbl_order_detail(fld_order_id, fld_pid, fld_qty, fld_uid, fld_price, fld_lastupdated)
					VALUES('<span style="color: #006699; font-weight: bold;">$next_fld_order_id</span>', '<span style="color: #006699; font-weight: bold;">{$product['productid']}</span>', '<span style="color: #006699; font-weight: bold;">{$product['qty']}</span>', '<span style="color: #006699; font-weight: bold;">{$product['unit']}</span>', 
					'<span style="color: #006699; font-weight: bold;">{$product['price']}</span>', NOW())&quot;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$query_id</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$sql</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$next_fld_order_id</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>	
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Here we have created a class <strong>&#8220;WebOrders&#8221;</strong>. It&#8217;s having two methods <strong>&#8220;_getStoreInfo&#8221;</strong> and <strong>&#8220;receiveNewOrder&#8221;</strong>. <strong>&#8220;_getStoreInfo&#8221;</strong> is the private method (We can create private method by prefixing &#8216;_&#8217; before function name). Its means no one can access this method of dervice. <strong>&#8220;receiveNewOrder&#8221;</strong> method is for receiving the new order request. Its taking <strong>&#8220;$order&#8221;</strong> associative array as paramater and return the new order ID.</p>
<p><strong>2. Access it using XML-RPC</strong><br />
We have create a web Service, now we need to access ir using XML-RPC. We need a XML-RPC library for calling the web service. I&#8217;m using this one <strong><a href="http://phpxmlrpc.sourceforge.net/#download">http://phpxmlrpc.sourceforge.net/#download</a></strong>. You can call the web service like this:-</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  	<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lib/xmlrpc.inc'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  	<span style="color: #000088;">$xmlrpc_client</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> xmlrpc_client<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/amfphp/xmlrpc.php&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'localhost'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">80</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  	<span style="color: #000088;">$xmlrpc_client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setDebug</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//this will print all the responses as they come back</span>
&nbsp;
  	<span style="color: #000088;">$order</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> stdClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  	<span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">storeid</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">total</span> <span style="color: #339933;">=</span> <span style="color:#800080;">100.50</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">tax</span> <span style="color: #339933;">=</span> <span style="color:#800080;">10.50</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">customer_name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Anil Chauhan'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'meetanilchauhan@varshyl.com'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">phone</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'9810713123'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">address</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'24 - Laxmi Nagar, Delhi'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">delivery</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'1'</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">note</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Test Note'</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #000088;">$order</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">products</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'productid'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">25</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'qty'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">3</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'unit'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'2'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'price'</span> <span style="color: #339933;">=&gt;</span> <span style="color:#800080;">30.00</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  	<span style="color: #000088;">$order</span> <span style="color: #339933;">=</span> php_xmlrpc_encode<span style="color: #009900;">&#40;</span><span style="color: #000088;">$order</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  	<span style="color: #000088;">$xmlrpc_message</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> xmlrpcmsg<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;WebOrders.receiveNewOrder&quot;</span><span style="color: #339933;">,</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$order</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  	<span style="color: #000088;">$xmlrpc_response</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$xmlrpc_client</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xmlrpc_message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$xmlrpc_response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">faultCode</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
  		<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$xmlrpc_response</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">faultString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  	<span style="color: #009900;">&#125;</span><span style="color: #b1b100;">else</span><span style="color: #009900;">&#123;</span>
  		<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Pingback successful&quot;</span><span style="color: #339933;">;</span>
  	<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Here, first we have included the <strong>&#8220;xmlrpc.inc&#8221;</strong> lilbrary. Then we have created the object of <strong>xmlrpc_client</strong>. We have also enabled the debug option using &#8220;$xmlrpc_client->setDebug(1);&#8221;. Make sure you switch off the debugging option on your production server.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/create-web-services-using-amfphp-and-xml-rpc/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

