<?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; Uncategorized</title>
	<atom:link href="http://www.akchauhan.com/category/uncategorized/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 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>
		<item>
		<title>Search Result</title>
		<link>http://www.akchauhan.com/search-result/</link>
		<comments>http://www.akchauhan.com/search-result/#comments</comments>
		<pubDate>Sun, 01 Feb 2009 12:10:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=520</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<div id="cse-search-results"></div>
<p><script type="text/javascript">
  var googleSearchIframeName = "cse-search-results";
  var googleSearchFormName = "cse-search-box";
  var googleSearchFrameWidth = 800;
  var googleSearchDomain = "www.google.com";
  var googleSearchPath = "/cse";
</script><br />
<script type="text/javascript" src="http://www.google.com/afsonline/show_afs_search.js"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/search-result/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

