<?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>Dimuthu's Blog &#187; php</title>
	<atom:link href="http://www.dimuthu.org/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dimuthu.org</link>
	<description>Waiting for your comments</description>
	<lastBuildDate>Wed, 21 Dec 2011 05:39:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<image>
  <link>http://www.dimuthu.org</link>
  <url>http://www.dimuthu.org/favicon.ico</url>
  <title>Dimuthu's Blog</title>
</image>
		<item>
		<title>PHP Web Services: Webinar From WSO2 And Zend</title>
		<link>http://www.dimuthu.org/blog/2010/05/19/php-web-services-webinar-from-wso2-and-zend/</link>
		<comments>http://www.dimuthu.org/blog/2010/05/19/php-web-services-webinar-from-wso2-and-zend/#comments</comments>
		<pubDate>Wed, 19 May 2010 13:30:25 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[SOA]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[webinar]]></category>
		<category><![CDATA[zend]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=1088</guid>
		<description><![CDATA[WSO2 and Zend jointly present a webinar titling &#8220;PHP Web Services: Why You Should Care&#8221; on 26th of May, 2010. The webinar will mainly focus on the following aspects, • Understand Web services development best practices • Discuss Web service myths and pitfalls • Learn about prominent PHP Web services extensions • Watch a demo [...]]]></description>
			<content:encoded><![CDATA[<p>WSO2 and Zend jointly present a webinar titling &#8220;<a href="http://wso2.org/library/webinars/2010/05/webinar-php-web-services-you-should-care">PHP Web Services: Why You Should Care</a>&#8221; on 26th of May, 2010. The webinar will mainly focus on the following aspects,<br />
• Understand Web services development best practices<br />
• Discuss Web service myths and pitfalls<br />
• Learn about prominent PHP Web services extensions<br />
• Watch a demo of building Web Services with both the Zend Framework and WSO2 Web Services Framework for PHP.</p>
<p>You can find more information about the webinar and the link to registration here, <a href="http://wso2.org/library/webinars/2010/05/webinar-php-web-services-you-should-care">http://wso2.org/library/webinars/2010/05/webinar-php-web-services-you-should-care</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2010/05/19/php-web-services-webinar-from-wso2-and-zend/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WSF/PHP Code First Approach: Returning an Array of String</title>
		<link>http://www.dimuthu.org/blog/2010/01/08/wsfphp-code-first-approach-returning-an-array-of-string/</link>
		<comments>http://www.dimuthu.org/blog/2010/01/08/wsfphp-code-first-approach-returning-an-array-of-string/#comments</comments>
		<pubDate>Fri, 08 Jan 2010 02:05:12 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[xml schema]]></category>
		<category><![CDATA[code first]]></category>
		<category><![CDATA[wsdl generation]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=1060</guid>
		<description><![CDATA[Here is a problem that many people have asked me how to do it. &#8220;Returning an array of string&#8221; with the code first approach. The API or WSDL generation annotation guide, http://wso2.org/project/wsf/php/2.0.0/docs/wsdl_generation_api.html contain all the things required in details. Here is an example of a service that return an array of string. &#60;?php /** splitMe [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a problem that many people have asked me how to do it. &#8220;Returning an array of string&#8221; with the code first approach. The API or WSDL generation annotation guide, <a href="http://wso2.org/project/wsf/php/2.0.0/docs/wsdl_generation_api.html">http://wso2.org/project/wsf/php/2.0.0/docs/wsdl_generation_api.html</a> contain all the things required in details. Here is an example of a service that return an array of string.</p>
<pre><span style="color: #000000; font-weight: bold;">&lt;?php</span>

<span style="color: #808080; font-style: italic;">/** splitMe function
 * @param string $string_to_split string to split
 * (maps to the xs:string XML schema type )
 * @return array of string $result split to array
 *(maps to the xs:double XML schema type )
 */</span>
<span style="color: #000000; font-weight: bold;">function</span> splitMe<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$string_to_split</span><span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>
    <span style="color: #b1b100;">return</span> <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"result"</span> =&gt; <a href="http://www.php.net/split"><span style="color: #000066;">split</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">":"</span>, <span style="color: #0000ff;">$string_to_split</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #66cc66;">}</span>

<span style="color: #0000ff;">$operations</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"splitMe"</span>=&gt;<span style="color: #ff0000;">"splitMe"</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$opParams</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"splitMe"</span>=&gt;<span style="color: #ff0000;">"MIXED"</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$svr</span> = <span style="color: #000000; font-weight: bold;">new</span> WSService<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"operations"</span>=&gt;<span style="color: #0000ff;">$operations</span>,
                           <span style="color: #ff0000;">"bindingStyle"</span>=&gt;<span style="color: #ff0000;">"doclit"</span>,
                           <span style="color: #ff0000;">"opParams"</span>=&gt;<span style="color: #0000ff;">$opParams</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$svr</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<span style="color: #000000; font-weight: bold;">?&gt;</span>
</pre>
<p>Note that the annotation corresponding to the return value.</p>
<pre> * @return array of spring $result split to array
</pre>
<p>This will generate an schema with an element of maxOccurs=&#8217;unbounded&#8217;. Note that you can get the wsdl from the &#8216;serviceurl?wsdl&#8217;.</p>
<pre><span style="font-weight: bold; color: black;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"splitMeResponse"</span><span style="font-weight: bold; color: black;">&gt;</span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;xsd:element</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"result"</span> <span style="color: #000066;">maxOccurs</span>=<span style="color: #ff0000;">"unbounded"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"xsd:string"</span><span style="font-weight: bold; color: black;">/&gt;</span></span>
        <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:sequence<span style="font-weight: bold; color: black;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:complexType<span style="font-weight: bold; color: black;">&gt;</span></span></span>
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/xsd:element<span style="font-weight: bold; color: black;">&gt;</span>
</span></span></pre>
<p>Now just generate a client for this service using wsdl2php and try invoke it. You will get an array of string as the response.</p>
<pre>    <span style="color: #0000ff;">$input</span> = <span style="color: #000000; font-weight: bold;">new</span> splitMe<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
    <span style="color: #0000ff;">$input</span>-&gt;<span style="color: #006600;">string_to_split</span> = <span style="color: #ff0000;">"a:b:c:d"</span>;

 
    <span style="color: #808080; font-style: italic;">// call the operation</span>
    <span style="color: #0000ff;">$response</span> = <span style="color: #0000ff;">$proxy</span>-&gt;<span style="color: #006600;">splitMe</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$input</span><span style="color: #66cc66;">)</span>;
    <a href="http://www.php.net/print_r"><span style="color: #000066;">print_r</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$response</span><span style="color: #66cc66;">)</span>;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2010/01/08/wsfphp-code-first-approach-returning-an-array-of-string/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Getting the size of BLOB in MySql</title>
		<link>http://www.dimuthu.org/blog/2010/01/06/getting-the-size-of-blob-in-mysql/</link>
		<comments>http://www.dimuthu.org/blog/2010/01/06/getting-the-size-of-blob-in-mysql/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 02:53:32 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[blob]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[OCTET_LENGTH]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=1049</guid>
		<description><![CDATA[If you want to store binary in database, you can use BLOB as the data type of that column. In Mysql you can use TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB depending on your space requirement. Here is an example of database table using BLOB as a column type. CREATE TABLE BloBTest ( id INT NOT NULL AUTO_INCREMENT, [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to store binary in database, you can use <a href="http://dev.mysql.com/doc/refman/5.0/en/blob.html">BLOB</a> as the data type of that column. In Mysql you can use TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB depending on your space requirement. Here is an example of database table using BLOB as a column type.</p>
<pre><span style="color: #993333; font-weight: bold;">CREATE</span> <span style="color: #993333; font-weight: bold;">TABLE</span> BloBTest <span style="color: #66cc66;">(</span>
    id INT <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span> <span style="color: #993333; font-weight: bold;">AUTO_INCREMENT</span>,
    filename VARCHAR<span style="color: #66cc66;">(</span> <span style="color: #cc66cc;">32</span> <span style="color: #66cc66;">)</span> <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>,
    content BLOB <span style="color: #993333; font-weight: bold;">NOT</span> <span style="color: #993333; font-weight: bold;">NULL</span>,
    <span style="color: #993333; font-weight: bold;">PRIMARY</span> <span style="color: #993333; font-weight: bold;">KEY</span> <span style="color: #66cc66;">(</span> id <span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">)</span></pre>
<p><strong>Storing Data</strong></p>
<p><strong>PHP:</strong></p>
<pre><span style="color: #0000ff;">$filename</span> = <span style="color: #ff0000;">"myimage.png"</span>;
<span style="color: #0000ff;">$filecontent</span> = <a href="http://www.php.net/file_get_contents"><span style="color: #000066;">file_get_contents</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$filename</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$filecontent_escaped</span> = <a href="http://www.php.net/mysql_real_escape_string"><span style="color: #000066;">mysql_real_escape_string</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$filecontent</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$sql</span> = <span style="color: #ff0000;">"INSERT INTO BloBTest(filename, content) "</span> +
       <span style="color: #ff0000;">"VALUES('$filename','$filecontent_escaped')"</span>;
<a href="http://www.php.net/mysql_query"><span style="color: #000066;">mysql_query</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$sql</span>, <span style="color: #0000ff;">$link</span><span style="color: #66cc66;">)</span>;</pre>
<p><strong> Java:</strong></p>
<pre><span style="color: #aaaadd; font-weight: bold;">String</span> filename = <span style="color: #ff0000;">"myimage.png"</span>;
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AInputStream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">InputStream</span></a> filecontent = <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AFileInputStream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">FileInputStream</span></a><span style="color: #66cc66;">(</span>filename<span style="color: #66cc66;">)</span>;

<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> sql = <span style="color: #ff0000;">"INSERT INTO BloBTest(filename, content) VALUES(?, ?)"</span>;

<span style="color: #993333;">int</span> size = filecontent.<span style="color: #006600;">available</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3APreparedStatement+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">PreparedStatement</span></a> ps = conn.<span style="color: #006600;">prepareStatement</span><span style="color: #66cc66;">(</span>sql<span style="color: #66cc66;">)</span>;
ps.<span style="color: #006600;">setString</span><span style="color: #66cc66;">(</span><span style="color: #cc66cc;">1</span>, filename<span style="color: #66cc66;">)</span>;
ps.<span style="color: #006600;">setBinaryStream</span><span style="color: #66cc66;">(</span><span style="color: #cc66cc;">2</span>, filecontent, size<span style="color: #66cc66;">)</span>;
ps.<span style="color: #006600;">executeUpdate</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</pre>
<p><strong>Retrieving Data</strong></p>
<p><strong>PHP</strong></p>
<pre><span style="color: #0000ff;">$sql</span> = <span style="color: #ff0000;">"SELECT filename, content FROM BloBTest"</span>;
<span style="color: #0000ff;">$result</span> = <a href="http://www.php.net/mysql_query"><span style="color: #000066;">mysql_query</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$sql</span>, <span style="color: #0000ff;">$link</span><span style="color: #66cc66;">)</span>;
<span style="color: #b1b100;">while</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$row</span> = <a href="http://www.php.net/mysql_fetch_assoc"><span style="color: #000066;">mysql_fetch_assoc</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$result</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>

    <span style="color: #0000ff;">$filename</span> = <span style="color: #0000ff;">$row</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">"filename"</span><span style="color: #66cc66;">]</span>;
    <span style="color: #0000ff;">$content</span> = <span style="color: #0000ff;">$row</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">"content"</span><span style="color: #66cc66;">]</span>;
    <span style="color: #0000ff;">$new_filename</span> = <span style="color: #ff0000;">"new_"</span> . <span style="color: #0000ff;">$filename</span>;
    file_put_contents<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$new_filename</span>, <span style="color: #0000ff;">$content</span><span style="color: #66cc66;">)</span>;
<span style="color: #66cc66;">}</span></pre>
<p><strong>Java</strong>:</p>
<pre><span style="color: #aaaadd; font-weight: bold;">String</span> sql = <span style="color: #ff0000;">"SELECT filename, content FROM BloBTest"</span>;

PrepareStatement ps  = conn.<span style="color: #006600;">prepareStatement</span><span style="color: #66cc66;">(</span>resourceContentSQL<span style="color: #66cc66;">)</span>;
<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AResultSet+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">ResultSet</span></a> result = ps.<span style="color: #006600;">executeQuery</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;

<span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span>result.<span style="color: #006600;">next</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">{</span>
    <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> filename = result.<span style="color: #006600;">getString</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"filename"</span><span style="color: #66cc66;">)</span>;
    <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AInputStream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">InputStream</span></a> contentStream = result.<span style="color: #006600;">getBinaryStream</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"content"</span><span style="color: #66cc66;">)</span>;
    <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">String</span></a> newFilename = <span style="color: #ff0000;">"new_"</span> + filename;
    <span style="color: #808080; font-style: italic;">// storing the input stream in the file</span>

    <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AOutputStream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">OutputStream</span></a> out=<span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AFileOutputStream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #aaaadd; font-weight: bold;">FileOutputStream</span></a><span style="color: #66cc66;">(</span>newFilename<span style="color: #66cc66;">)</span>;
    <span style="color: #993333;">byte</span> buf<span style="color: #66cc66;">[</span><span style="color: #66cc66;">]</span>=<span style="color: #000000; font-weight: bold;">new</span> <span style="color: #993333;">byte</span><span style="color: #66cc66;">[</span><span style="color: #cc66cc;">1024</span><span style="color: #66cc66;">]</span>;
    <span style="color: #993333;">int</span> len;
    <span style="color: #b1b100;">while</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">(</span>len=contentStream.<span style="color: #006600;">read</span><span style="color: #66cc66;">(</span>buf<span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>&gt;<span style="color: #cc66cc;">0</span><span style="color: #66cc66;">)</span>

    out.<span style="color: #006600;">write</span><span style="color: #66cc66;">(</span>buf,<span style="color: #cc66cc;">0</span>,len<span style="color: #66cc66;">)</span>;
    out.<span style="color: #006600;">close</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
<span style="color: #66cc66;">}</span></pre>
<p><strong>Retrieving the Size of the Blob</strong></p>
<p>After you store your data as a blob, you can manipulate or query the data with some of the in-built <a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html">String functions</a> in mysql. For an example if you want to query the size of the blob you just stored, you can use <a href="http://dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_octet-length">OCTET_LENGTH</a> function. Here is an example,  (this will give you the size in bytes.)</p>
<pre><span style="color: #993333; font-weight: bold;">SELECT</span> OCTET_LENGTH<span style="color: #66cc66;">(</span>content<span style="color: #66cc66;">)</span> <span style="color: #993333; font-weight: bold;">FROM</span> BloBTest <span style="color: #993333; font-weight: bold;">WHERE</span> filename=<span style="color: #ff0000;">'myimage.png'</span></pre>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 228px; width: 1px; height: 1px;">
<pre>.</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2010/01/06/getting-the-size-of-blob-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Case Study &#8211; PHP Data Services To Extract Content from Drupal Database</title>
		<link>http://www.dimuthu.org/blog/2009/02/13/case-study-php-data-services-to-extract-content-from-drupal-database/</link>
		<comments>http://www.dimuthu.org/blog/2009/02/13/case-study-php-data-services-to-extract-content-from-drupal-database/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 16:40:11 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[case study]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[mashup server]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=930</guid>
		<description><![CDATA[In this case study &#8220; PHP Data Services Extract Content from Drupal Database&#8220;, I intended to present how Data Service concepts can be applied to extract data with marketing value from  a CMS database and publish it as web services.  I used the drupal instance deployed at http://wso2.org as the CMS for the use case. [...]]]></description>
			<content:encoded><![CDATA[<p>In this case study &#8220;<a href="http://wso2.org/library/case-studies/case-study-php-data-services-extract-drupal-database"> PHP Data Services Extract Content from Drupal Database</a>&#8220;, I intended to present how Data Service concepts can be applied to extract data with marketing value from  a CMS database and publish it as web services.  I used the drupal instance deployed at <a href="http://wso2.org">http://wso2.org</a> as the CMS for the use case. And as the data service framework, I used <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> data services library, as it requires minimum changes to the existing infrastructure (the LAMP stack).</p>
<p>The case study also talks about how to consume the data service by any third party mashup to present textual/ graphical views of analyzed data. These mashups can be extended up to intergreate with social networks like facebook, twitter and etc to communicate back and forth a wider community and may be it can be used to track the distribution of active users using Google maps. Simply it makes easier to analyze business data + engagement with the community.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2009/02/13/case-study-php-data-services-to-extract-content-from-drupal-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making Web Requests Using Curl From C and PHP</title>
		<link>http://www.dimuthu.org/blog/2009/01/28/making-web-requests-using-curl-from-c-and-php/</link>
		<comments>http://www.dimuthu.org/blog/2009/01/28/making-web-requests-using-curl-from-c-and-php/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 16:07:14 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[libcurl]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web requests]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=906</guid>
		<description><![CDATA[libcurl is a famous C library which can be used to transfer data through http/tcp or any custom protocols. It has a very easy to use API to make web requests programatically. PHP has an extension that wraps the libcurl API and provide a very convenient API to PHP programmers. Normally PHP has a lot [...]]]></description>
			<content:encoded><![CDATA[<p>libcurl is a famous C library which can be used to transfer data through http/tcp or any custom protocols. It has a very easy to use API to make web requests programatically.</p>
<p>PHP has an extension that wraps the libcurl API and provide a very convenient API to PHP programmers.</p>
<p>Normally PHP has a lot of functions that are available in C standard libraries. For an example you have the <em>strlen</em> in both C and PHP that gives you the length of a string. But PHP has additional helper functions that allows programmers to manipulate strings easily. For an example you can compare strings in PHP using <em>strcmp</em> function as in C style. Or you can simply use &#8220;==&#8221; operator. </p>
<p>Similarly libcurl APi for PHP  is very similar to the C API. But it has specially made to suit for the PHP language.</p>
<p>Here is a C code that make a web request to my blog and print it in the console.</p>
<pre class="c"><span style="color: #339933;">#include &lt;curl/curl.h&gt;</span>
<span style="color: #339933;">#include &lt;curl/types.h&gt;</span>
<span style="color: #339933;">#include &lt;curl/easy.h&gt;</span>
<span style="color: #339933;">#include &lt;string.h&gt;</span>

<span style="color: #808080; font-style: italic;">/* function prototypes to define later */</span>
<span style="color: #993333;">char</span> *do_web_request<span style="color: #66cc66;">(</span><span style="color: #993333;">char</span> *url<span style="color: #66cc66;">)</span>;
size_t <span style="color: #993333;">static</span> write_callback_func<span style="color: #66cc66;">(</span><span style="color: #993333;">void</span> *buffer,
                        size_t size,
                        size_t nmemb,
                        <span style="color: #993333;">void</span> *userp<span style="color: #66cc66;">)</span>;

<span style="color: #808080; font-style: italic;">/* the main function invoking */</span>
<span style="color: #993333;">int</span> main<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>
    <span style="color: #993333;">char</span> *url = <span style="color: #ff0000;">"http://dimuthu.org"</span>;
    <span style="color: #993333;">char</span> *content = <span style="color: #000000; font-weight: bold;">NULL</span>;

    content = do_web_request<span style="color: #66cc66;">(</span>url<span style="color: #66cc66;">)</span>;

    <a href="http://www.opengroup.org/onlinepubs/009695399/functions/printf.html"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"%s"</span>, content<span style="color: #66cc66;">)</span>;
<span style="color: #66cc66;">}</span>

<span style="color: #808080; font-style: italic;">/* the function to return the content for a url */</span>
<span style="color: #993333;">char</span> *do_web_request<span style="color: #66cc66;">(</span><span style="color: #993333;">char</span> *url<span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>
    <span style="color: #808080; font-style: italic;">/* keeps the handle to the curl object */</span>
    CURL *curl_handle = <span style="color: #000000; font-weight: bold;">NULL</span>;
    <span style="color: #808080; font-style: italic;">/* to keep the response */</span>
    <span style="color: #993333;">char</span> *response = <span style="color: #000000; font-weight: bold;">NULL</span>;

    <span style="color: #808080; font-style: italic;">/* initializing curl and setting the url */</span>
    curl_handle = curl_easy_init<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;
    curl_easy_setopt<span style="color: #66cc66;">(</span>curl_handle, CURLOPT_URL, url<span style="color: #66cc66;">)</span>;
    curl_easy_setopt<span style="color: #66cc66;">(</span>curl_handle, CURLOPT_HTTPGET, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">)</span>;

    <span style="color: #808080; font-style: italic;">/* follow locations specified by the response header */</span>
    curl_easy_setopt<span style="color: #66cc66;">(</span>curl_handle, CURLOPT_FOLLOWLOCATION, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">)</span>;

    <span style="color: #808080; font-style: italic;">/* setting a callback function to return the data */</span>
    curl_easy_setopt<span style="color: #66cc66;">(</span>curl_handle, CURLOPT_WRITEFUNCTION, write_callback_func<span style="color: #66cc66;">)</span>;

    <span style="color: #808080; font-style: italic;">/* passing the pointer to the response as the callback parameter */</span>
    curl_easy_setopt<span style="color: #66cc66;">(</span>curl_handle, CURLOPT_WRITEDATA, &amp;response<span style="color: #66cc66;">)</span>;

    <span style="color: #808080; font-style: italic;">/* perform the request */</span>
    curl_easy_perform<span style="color: #66cc66;">(</span>curl_handle<span style="color: #66cc66;">)</span>;

    <span style="color: #808080; font-style: italic;">/* cleaning all curl stuff */</span>
    curl_easy_cleanup<span style="color: #66cc66;">(</span>curl_handle<span style="color: #66cc66;">)</span>;

    <span style="color: #b1b100;">return</span> response;
<span style="color: #66cc66;">}</span>

<span style="color: #808080; font-style: italic;">/* the function to invoke as the data recieved */</span>
size_t <span style="color: #993333;">static</span> write_callback_func<span style="color: #66cc66;">(</span><span style="color: #993333;">void</span> *buffer,
                        size_t size,
                        size_t nmemb,
                        <span style="color: #993333;">void</span> *userp<span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>
    <span style="color: #993333;">char</span> **response_ptr =  <span style="color: #66cc66;">(</span><span style="color: #993333;">char</span>**<span style="color: #66cc66;">)</span>userp;

    <span style="color: #808080; font-style: italic;">/* assuming the response is a string */</span>
    *response_ptr = strndup<span style="color: #66cc66;">(</span>buffer, <span style="color: #66cc66;">(</span>size_t<span style="color: #66cc66;">)</span><span style="color: #66cc66;">(</span>size *nmemb<span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #66cc66;">}</span></pre>
<p>Lets see how simple it is with PHP.</p>
<pre class="php"><span style="color: #000000; font-weight: bold;">&lt;?php</span>

<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> do_web_request<span style="color: #66cc66;">(</span><span style="color: #ff0000;">"http://dimuthu.org/"</span><span style="color: #66cc66;">)</span>;

<span style="color: #808080; font-style: italic;">/* the function to make the request */</span>
<span style="color: #000000; font-weight: bold;">function</span> do_web_request<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$url</span><span style="color: #66cc66;">)</span>
<span style="color: #66cc66;">{</span>
    <span style="color: #808080; font-style: italic;">/* initializing curl */</span>
    <span style="color: #0000ff;">$curl_handle</span> = curl_init<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$url</span><span style="color: #66cc66;">)</span>;

    <span style="color: #808080; font-style: italic;">/* set this option the curl_exec function return the response */</span>
    curl_setopt<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$curl_handle</span>, CURLOPT_RETURNTRANSFER, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">)</span>;

    <span style="color: #808080; font-style: italic;">/* follow the redirection */</span>
    curl_setopt<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$curl_handle</span>, CURLOPT_FOLLOWLOCATION, <span style="color: #cc66cc;">1</span><span style="color: #66cc66;">)</span>;

    <span style="color: #808080; font-style: italic;">/* invoke the request */</span>
    <span style="color: #0000ff;">$response</span> = curl_exec<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$curl_handle</span><span style="color: #66cc66;">)</span>;

    <span style="color: #808080; font-style: italic;">/* cleanup curl stuff */</span>
    curl_close<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$curl_handle</span><span style="color: #66cc66;">)</span>;

    <span style="color: #b1b100;">return</span> <span style="color: #0000ff;">$response</span>;
<span style="color: #66cc66;">}</span>

<span style="color: #000000; font-weight: bold;">?&gt;</span></pre>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2009/01/28/making-web-requests-using-curl-from-c-and-php/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Article Introducing PHP Data Services</title>
		<link>http://www.dimuthu.org/blog/2009/01/05/article-introducing-php-data-services/</link>
		<comments>http://www.dimuthu.org/blog/2009/01/05/article-introducing-php-data-services/#comments</comments>
		<pubDate>Mon, 05 Jan 2009 13:06:55 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[DataServices]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[introduction]]></category>
		<category><![CDATA[SOAP]]></category>
		<category><![CDATA[WS-*]]></category>
		<category><![CDATA[ws-security]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=900</guid>
		<description><![CDATA[Now you can view the article I wrote titling &#8220;Introduction to PHP Data Services&#8220;. There I explain how you can design and implement Data Services in PHP using WSF/PHP Data Services Library. This article covers, Designing your Data Service API. Writing the Data Service. Deploying and Testing Data Service. Make the Data Service available in [...]]]></description>
			<content:encoded><![CDATA[<p>Now you can view the article I wrote titling &#8220;<a href="http://wso2.org/library/articles/introduction-php-data-services">Introduction to PHP Data Services</a>&#8220;. There I explain how you can design and implement Data Services in PHP using <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> Data Services Library.</p>
<p>This article covers,</p>
<ol>
<li>Designing your Data Service API.</li>
<li>Writing the Data Service.</li>
<li>Deploying and Testing Data Service.</li>
<li>Make the Data Service available in both SOAP and RESTful form.</li>
<li>Use of WS-* features in your Data Service.</li>
</ol>
<p>If you are thinking of adapting SOA in to your database backed PHP applications, this article will be a good starting point.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2009/01/05/article-introducing-php-data-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RESTful PHP Web Services &#8211; Book Review</title>
		<link>http://www.dimuthu.org/blog/2009/01/01/restful-php-web-services-book-review/</link>
		<comments>http://www.dimuthu.org/blog/2009/01/01/restful-php-web-services-book-review/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 05:22:46 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[design]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[Book]]></category>
		<category><![CDATA[clients]]></category>
		<category><![CDATA[services]]></category>
		<category><![CDATA[Zend Framework]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=865</guid>
		<description><![CDATA[PHP is one of the famous choice, when it comes to develop a web site. As the web evolve with the emerge of web service, REST (REpresentational State Transfer) concepts, the PHP language is also adapted to the new requirements specially with the availability of new SOA (Service Oriented Architecture), REST frameworks and libraries. Anyway [...]]]></description>
			<content:encoded><![CDATA[<p>PHP is one of the famous choice, when it comes to develop a web site. As the web evolve with the emerge of web service, REST (REpresentational State Transfer) concepts, the PHP language is also adapted to the new requirements specially with the availability of new SOA (Service Oriented Architecture), REST frameworks and libraries. Anyway there were hardly any guides, references or samples that properly describe the methodologies of developing REST applications using PHP.</p>
<p>The book &#8220;<a href="http://www.packtpub.com/restful-php-web-services/book">RESTful PHP Web Services</a>&#8216; by <a href="http://samisa-abeysinghe.blogspot.com/">Samisa Abeysinghe</a> certainly fill this gap. It can be used as a step by step guideline for newbies to learn the concepts and write simple RESTful PHP applications and Mashups. And even experienced developers would find this a great reference to keep nearby while working with RESTful Web Services in PHP. And it has lot of code samples, utility functions that developers can use it in their applications.</p>
<p><a href="http://www.packtpub.com/restful-php-web-services/book"><img title="RESTful PHP Web Services - Samisa Abeysinghe" src="http://images.packtpub.com/images/full/1847195520.jpg" alt="RESTful PHP Web Services - Samisa Abeysinghe" width="200" /></a></p>
<p><strong>About the Author</strong></p>
<p><a href="http://samisa-abeysinghe.blogspot.com/">Samisa Abeysinghe</a> is a well recognized name in the web services world. He lead the development of <a href="http://ws.apache.org/axis2/c/">Apache Axis2/C</a> and <a href="http://wso2.org/projects/wsf/php">WSO2 WSF/PHP</a>, two famous open source web service frameworks for &#8216;C&#8217; and PHP. In addition to his deep knowledge in the subject, his experience in involving with the community and the enterprise for years and working as a lecturer in universities, should have influenced a lot in writing this book.</p>
<p><strong>The Arrangement and the Content</strong></p>
<p>The <a href="http://www.packtpub.com/article/restful-php-web-services-table-of-contents">arrangement of the book</a> is done really well to make sure the reader can go through it in the right sequence. All the content is bundled just within 200 pages. So you don&#8217;t need to allocate a lot of time to go through the whole book. It is organized into 7 chapters and two appendixes which are mostly independent from each other.</p>
<p>The first chapter is completely devoted to explain the concepts of RESTful web services. It basically explains what is RESTful web service and why it is needed. And it briefly mentions about the currently available REST Frameworks for PHP.</p>
<p>The second chapter introduce some PHP codes that do REST web service requests and handles the XML responses using both DOM and SimpleXML APIs. And in the third chapter it shows more code samples specially about consuming real world web services like BBC, Yahoo and an earthquakes information service. Theses codes are written as mashups mostly combining two services to produce more meaningful information.</p>
<p>The forth chapter is about  designing and writing web service providers. Its counterpart, writing web service consumers is described in the chapter five. There it demonstrate a library system that operate using RESTful webservices. You can map this example to any system that you may like to develop to run with RESTful web services.  The chapter five of the book is available as a free download, <a href="http://www.dimuthu.org/wp-content/uploads/2008/12/restful-php-webservices_sample-chapter.pdf">RESTful PHP Web Services &#8211; Chapter 5</a>.</p>
<p>The forth and fifth chapters are not using any framework to write the sample codes on consuming and providing web services. But in the sixth chapter it shows the use of <a href="http://framework.zend.com/">Zend framework</a> to do write them. There it rewrites the same example (The RESTful library system) in MVC (Model -View &#8211; Controller) approach using the functionalities of Zend framework. (In fact the View in the service is omitted).</p>
<p>The seventh chapter is about debugging web services. Debugging is a much needed step in any software development cycle. So if you are a newbie, you should read this chapter before start writing any of your own code. This introduces tools and methodologies to make your debugging easy and effective.</p>
<p>The book contains two appendixes. They are too really useful as the chapters of the book. In the first appendix it explains another REST web service framework, <a href="http://wso2.org/projects/wsf/php">WSO2 Web Services Framework for PHP (WSF/PHP)</a>. To demonstrate it uses, some selected functionalities of the example library system (that is mentioned in chapters 4, 5, 6) is re-implemented using WSF/PHP. And it shows you how you can convert this RESTful system to a SOAP system in a minute. The second appendix provides you a code of a class (RESTClient), that you can use in consuming web services very effectively.</p>
<p><strong>Recommended Readers<br />
</strong></p>
<p>This book assume you have some knowledge in PHP. But it doesn&#8217;t require you to know anything related to web services, REST or XML. As you read the first few chapters, you will have a good understanding on the concepts and the basic applications of REST and XML using PHP. And the later chapters will guide to get deeper knowledge in writing complex and real world applications.</p>
<p>If you are a professional developer, you can skip the introduction chapters and jump directly to where you need to refer. For an example, if you use this book as a reference in designing and developing RESTful web service providers, you can directly read the chapter4 &#8211; Resource Oriented Services, chapter6- Resource Oriented Clients and Services with Zend Framework and probably the chapter 7 &#8211; Debugging Web Services.</p>
<p>This book contains the same example system (the library system) written in three different approaches, first without using any framework support, second using the Zend Framework, third using WSF/PHP. Each of them has its own pros and cons. So if you want to determine the approach more suitable to your requirements, or thinking of migrating from one to another, this book will be an ideal resource for you.</p>
<p>As you may have already noticed, this book contains lot of code samples. All the concepts are followed by simple code samples that explain the concept. In appendix it gives you a complete code for RESTClient class that you can use to call any REST service. Apart from the code of the example library system written using different frameworks, it has lot of codes for calling public web service APIs. And the explanation of the code is also done really well.</p>
<p>So it is clear this book is more targetting readers who like to implement PHP RESTful Systems in practice. And it covers enough concepts that you needed to know in writing practicle applications. So this book can take you from the zero knowlege to a deeper knowlege of RESTful PHP Web Services.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2009/01/01/restful-php-web-services-book-review/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Data Services with PostgreSQL</title>
		<link>http://www.dimuthu.org/blog/2008/12/07/php-data-services-with-postgresql/</link>
		<comments>http://www.dimuthu.org/blog/2008/12/07/php-data-services-with-postgresql/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 12:56:19 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[2 minutes guide]]></category>
		<category><![CDATA[DataServices]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[WSDL]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[data services]]></category>
		<category><![CDATA[DataService]]></category>
		<category><![CDATA[pdo_pgsql]]></category>
		<category><![CDATA[pgsql]]></category>
		<category><![CDATA[postgresql]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=771</guid>
		<description><![CDATA[LAMP (Linux + Apache + Mysql + PHP) stack powers many servers in the Internet today. For a LAMP  server, PostgreSQL could be the first alternative to Mysql. Similar to PHP + MySQL,  PHP + PostgreSQL too can be easily used in to host data services. Here are the steps to do it. If you [...]]]></description>
			<content:encoded><![CDATA[<p>LAMP (Linux + Apache + Mysql + PHP) stack powers many servers in the Internet today. For a LAMP  server, PostgreSQL could be the first alternative to Mysql. Similar to PHP + MySQL,  PHP + PostgreSQL too can be easily used in to host data services. Here are the steps to do it.</p>
<ol>
<li> If you already don&#8217;t have Apache + PHP + PostgreSQL download them from the following locations. Apache &#8211; <a href="http://httpd.apache.org/download.cgi">http://httpd.apache.org/download.cgi</a>, PHP &#8211; <a href="http://php.net">http://php.net</a> and PostgreSQL &#8211; <a href="http://www.postgresql.org/download/">http://www.postgresql.org/download/</a></li>
<li> You have to enable the PHP pdo_pgsql, pdo and pgsql plugins. Read <a href="http://www.php.net/manual/en/pgsql.setup.php">here </a>for the instructions to setup these libraries. (For an example: if you are windows you have to set the system &#8216;PATH&#8217; variable to the &lt;postgresql_installed_dir&gt;/bin directory.</li>
<li> If you already don&#8217;t have <a href="http://wso2.org/projects/wsf/php">WSF/PHP,</a> download and install it according to the guidelines provided in <a href="http://wso2.org/project/wsf/php/2.0.0/docs/install_guide.html">wsf/php installation guide</a>.<em>NOTE: You can check pdo_pgsql and wsf/php has properly installed with the help of phpinfo() function.</em></li>
<li> Now lets start with creating a sample Database table. For this example I created a database called &#8216;workshop&#8217;, schema called &#8216;workshop&#8217; and inside there the table &#8216;Employee&#8217; with the following schema.<br />
<table border="1">
<tbody>
<tr style="background: #dddddd">
<td>Column Name</td>
<td>Column Type</td>
</tr>
<tr>
<td>employId</td>
<td>integer</td>
</tr>
<tr>
<td>name</td>
<td>character varying</td>
</tr>
<tr>
<td>email</td>
<td>character varying</td>
</tr>
<tr>
<td>jobTitle</td>
<td>character varying</td>
</tr>
<tr>
<td>project</td>
<td>character varying</td>
</tr>
</tbody>
</table>
<p><em>Note: You can use <a href="http://phppgadmin.sourceforge.net/">phpPgAdmin</a> (web based) or <a href="http://www.pgadmin.org/">pgAdmin III </a>to create tables from GUI </em></li>
<li> Then you can write a small php script to expose the data in the above table as a web service.
<pre class="php"><span style="font-weight: bold; color: #000000;">&lt;?php</span>

<span style="font-style: italic; color: #808080;">//Including the Data Services library</span>
<span style="color: #b1b100;">require_once</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"wso2/DataServices/DataService.php"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// Including the connection information (i.e. PGSQUL USERNAME</span>
<span style="font-style: italic; color: #808080;">// and PGSQL_PASSWORD) for my PGSQL Connection</span>
<span style="color: #b1b100;">require_once</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"constants.php"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// database configurations</span>
<span style="color: #0000ff;">$config</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
		<span style="color: #ff0000;">"db"</span> =&gt; <span style="color: #ff0000;">"pgsql"</span>,
		<span style="color: #ff0000;">"username"</span> =&gt; PGSQL_USERNAME,
		<span style="color: #ff0000;">"password"</span> =&gt; PGSQL_PASSWORD,
		<span style="color: #ff0000;">"dbname"</span> =&gt; <span style="color: #ff0000;">"workshop"</span>,
		<span style="color: #ff0000;">"dbhost"</span> =&gt; <span style="color: #ff0000;">"localhost"</span>
		<span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$output_format</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
                    <span style="color: #ff0000;">"resultElement"</span> =&gt; <span style="color: #ff0000;">"employees"</span>,
                    <span style="color: #ff0000;">"rowElement"</span> =&gt; <span style="color: #ff0000;">"employee"</span>,
                    <span style="color: #ff0000;">"elements"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
			    <span style="color: #ff0000;">"id"</span> =&gt; <span style="color: #ff0000;">"employeeId"</span>,
                            <span style="color: #ff0000;">"name"</span> =&gt; <span style="color: #ff0000;">"name"</span>,
                            <span style="color: #ff0000;">"email"</span> =&gt; <span style="color: #ff0000;">"email"</span>,
                            <span style="color: #ff0000;">"jobTitle"</span> =&gt; <span style="color: #ff0000;">"jobTitle"</span>,
                            <span style="color: #ff0000;">"project"</span> =&gt; <span style="color: #ff0000;">"project"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$sql</span> = <span style="color: #ff0000;">"SELECT * FROM workshop.Employees"</span>;

<span style="color: #0000ff;">$get_employees_op</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"outputFormat"</span> =&gt; <span style="color: #0000ff;">$output_format</span>, <span style="color: #ff0000;">"sql"</span> =&gt; <span style="color: #0000ff;">$sql</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$get_employees_url</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"HTTPMethod"</span> =&gt; <span style="color: #ff0000;">"GET"</span>, <span style="color: #ff0000;">"RESTLocation"</span> =&gt; <span style="color: #ff0000;">"employees"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// list of operations</span>
<span style="color: #0000ff;">$operations</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
                <span style="color: #ff0000;">"getEmployees"</span> =&gt; <span style="color: #0000ff;">$get_employees_op</span>,
                <span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// list of rest url mappping (operation =&gt; url)</span>
<span style="color: #0000ff;">$restmap</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
                <span style="color: #ff0000;">"getEmployees"</span> =&gt; <span style="color: #0000ff;">$get_employees_url</span>,
                <span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// creating DSService and reply</span>
<span style="color: #0000ff;">$service</span> = <span style="font-weight: bold; color: #000000;">new</span> DataService<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
         <span style="color: #ff0000;">"config"</span> =&gt; <span style="color: #0000ff;">$config</span>,
         <span style="color: #ff0000;">"operations"</span> =&gt; <span style="color: #0000ff;">$operations</span>, <span style="color: #ff0000;">"RESTMapping"</span>=&gt;<span style="color: #0000ff;">$restmap</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;
<span style="color: #0000ff;">$service</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</pre>
<pre class="php"><span style="font-weight: bold; color: #000000;">?&gt;</span></pre>
</li>
<li> We just wrote a PostgreSQL Data Services that provides its service as both REST and SOAP form. To deploy this service, We just need to copy this in to the web root directory. And the web URL for the script will be the endpoint to the web service.</li>
<li>We can test the service either by calling its SOAP interface, which we may need to write a small SOAP client or by calling its REST interface, which only need a GET request from the browser. Say my script name is &#8220;my_dataservice.php&#8221; and I&#8217;ve put it in the web root directory, then the URL to call the REST interface of the service is
<pre>http://localhost/my_dataservice.php/employees</pre>
</li>
</ol>
<p><strong>WSDL Generation for PostgreSQL Data Service</strong><br />
You can get the WSDL for the service from the URL formed adding the suffix &#8220;?wsdl&#8221; (or &#8220;?wsdl2&#8243; to wsdl v2.0)  to the service URL,</p>
<pre>http://localhost/my_dataservice.php?wsdl</pre>
<p>Here all the schema data types are shown as xsd:anyType, which may not be the behavior that you want. In fact you can provide the schema data types to the fields from the code itself. Lets change the $outputFormat variable to provide the schema information as well using the following code snip.</p>
<pre class="php"><span style="color: #0000ff;">$output_format</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
                    <span style="color: #ff0000;">"resultElement"</span> =&gt; <span style="color: #ff0000;">"employees"</span>,
                    <span style="color: #ff0000;">"rowElement"</span> =&gt; <span style="color: #ff0000;">"employee"</span>,
                    <span style="color: #ff0000;">"elements"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
			    <span style="color: #ff0000;">"id"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"column"</span> =&gt; <span style="color: #ff0000;">"employeeId"</span>,
		    			  <span style="color: #ff0000;">"xsdType"</span> =&gt; <span style="color: #ff0000;">"xsd:int"</span><span style="color: #66cc66;">)</span>,
			    <span style="color: #ff0000;">"name"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"column"</span> =&gt; <span style="color: #ff0000;">"name"</span>,
		    			  <span style="color: #ff0000;">"xsdType"</span> =&gt; <span style="color: #ff0000;">"xsd:string"</span><span style="color: #66cc66;">)</span>,
			    <span style="color: #ff0000;">"email"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"column"</span> =&gt; <span style="color: #ff0000;">"email"</span>,
		    			  <span style="color: #ff0000;">"xsdType"</span> =&gt; <span style="color: #ff0000;">"xsd:string"</span><span style="color: #66cc66;">)</span>,
			    <span style="color: #ff0000;">"jobTitle"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"column"</span> =&gt; <span style="color: #ff0000;">"jobTitle"</span>,
		    			  <span style="color: #ff0000;">"xsdType"</span> =&gt; <span style="color: #ff0000;">"xsd:string"</span><span style="color: #66cc66;">)</span>,
			    <span style="color: #ff0000;">"project"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"column"</span> =&gt; <span style="color: #ff0000;">"project"</span>,
		    			  <span style="color: #ff0000;">"xsdType"</span> =&gt; <span style="color: #ff0000;">"xsd:string"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p>Note that you provide the xsd type for each field explicitly. In fact this change is not needed for mysql pdo extension since it allows identifying field types programatically. Since this feature is not available in all the other pdo drivers, we have to explicitly give xsd type information for them.</p>
<p>If you wan to provide data services with SQLite or MSSQL, You can check my other posts on <a href="http://www.dimuthu.org/blog/2008/10/04/mssqlmicrosoft-sql-data-services-in-php/">MSSQL(Microsoft SQL) Data Services In PHP</a> and <a href="http://www.dimuthu.org/blog/2008/10/05/data-services-with-sqlite-in-php/">Data Services with SQLite in PHP</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/12/07/php-data-services-with-postgresql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Steps to Convert a SQL Query to a Data Service</title>
		<link>http://www.dimuthu.org/blog/2008/11/27/steps-to-convert-sql-query-to-a-data-service/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/27/steps-to-convert-sql-query-to-a-data-service/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 17:48:31 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[DataServices]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[data service]]></category>
		<category><![CDATA[sql query]]></category>
		<category><![CDATA[Web Service]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=741</guid>
		<description><![CDATA[With WSF/PHP Data Service library, you can convert a SQL query to a Data Service very easily in few steps. Decide your SQL query first, For the query you may require some input parameters, and you have to decide what should be returned by the query, Say your query is $sql_query = "SELECT name, age, [...]]]></description>
			<content:encoded><![CDATA[<p>With <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> Data Service library, you can convert a SQL query to a Data Service very easily in few steps.</p>
<ol>
<li>Decide your SQL query first, For the query you may require some input parameters, and you have to decide what should be returned by the query, Say your query is
<pre><span style="color: #0000ff;">$sql_query</span> = <span style="color: #ff0000;">"SELECT name, age, email FROM users where country = ?"</span>;</pre>
<p>Then the &#8220;country&#8221; is our input parameter and the name, age, email are our return values.</li>
<li>Define the input Format. For the above query it will be something like,
<pre class="php"><span style="color: #0000ff;">$inputFormat</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"country"</span> =&gt; <span style="color: #ff0000;">"INT"</span><span style="color: #66cc66;">)</span>;</pre>
</li>
<li>Define the output format. We are giving the name &#8220;Users&#8221; for the out most wrapper element and the name &#8220;user&#8221; for the wrapper element of each user. Here is how we define it,
<pre class="php"><span style="color: #0000ff;">$outputFormat</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"resultElement"</span> =&gt; <span style="color: #ff0000;">"users"</span>,
                <span style="color: #ff0000;">"rowElement"</span> =&gt; <span style="color: #ff0000;">"user"</span>,
                <span style="color: #ff0000;">"elements"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
                            <span style="color: #ff0000;">"name"</span> =&gt; <span style="color: #ff0000;">"name"</span>,
                            <span style="color: #ff0000;">"age"</span> =&gt; <span style="color: #ff0000;">"age"</span>,
                            <span style="color: #ff0000;">"email"</span> =&gt; <span style="color: #ff0000;">"email"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p>For this output format, our expected result payload would be like,</p>
<pre class="xml"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;users<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;user<span style="font-weight: bold; color: black;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;name<span style="font-weight: bold; color: black;">&gt;</span></span></span>xxx<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;age<span style="font-weight: bold; color: black;">&gt;</span></span></span>23<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/age<span style="font-weight: bold; color: black;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>xxx@xxx.xx<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/user<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;user<span style="font-weight: bold; color: black;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;name<span style="font-weight: bold; color: black;">&gt;</span></span></span>yyy<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/name<span style="font-weight: bold; color: black;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;age<span style="font-weight: bold; color: black;">&gt;</span></span></span>23<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/age<span style="font-weight: bold; color: black;">&gt;</span></span></span>
     <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;email<span style="font-weight: bold; color: black;">&gt;</span></span></span>yyy@yyy.yy<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/email<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/user<span style="font-weight: bold; color: black;">&gt;</span></span></span>
  ....
<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/users<span style="font-weight: bold; color: black;">&gt;</span></span></span></pre>
</li>
<li> Define your operation using the sql query, input and output formats.
<pre class="php"><span style="color: #0000ff;">$operations</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"getUsersByCountry"</span> =&gt; <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
                              <span style="color: #ff0000;">"inputFormat"</span> =&gt; <span style="color: #0000ff;">$inputFormat</span>,
                              <span style="color: #ff0000;">"sql"</span> =&gt; <span style="color: #0000ff;">$sql_query</span>,
                              <span style="color: #ff0000;">"outputFormat"</span> =&gt; <span style="color: #0000ff;">$outputFormat</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
</li>
<li> Define your database configuration in an array like this,
<pre class="php"><span style="color: #0000ff;">$config</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
    <span style="color: #ff0000;">"db"</span> =&gt; <span style="color: #ff0000;">"mysql"</span>, <span style="font-style: italic; color: #808080;">// your db engine</span>
    <span style="color: #ff0000;">"username"</span> =&gt; <span style="color: #ff0000;">"myname"</span>, <span style="font-style: italic; color: #808080;">// name &amp; password for the db server</span>
    <span style="color: #ff0000;">"password"</span> =&gt; <span style="color: #ff0000;">"mypasswd"</span>,
    <span style="color: #ff0000;">"dbname"</span> =&gt; <span style="color: #ff0000;">"db"</span>, <span style="font-style: italic; color: #808080;">// the db</span>
    <span style="color: #ff0000;">"dbhost"</span> =&gt; <span style="color: #ff0000;">"localhost"</span><span style="color: #66cc66;">)</span>;</pre>
</li>
<li> Create a DataService instance using the database configuration and the operations we just created. And call DataServices reply method.
<pre class="php"><span style="color: #0000ff;">$ds_service</span> = <span style="font-weight: bold; color: #000000;">new</span> DataService<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span>
               <span style="color: #ff0000;">"config"</span> =&gt; <span style="color: #0000ff;">$config</span>,
               <span style="color: #ff0000;">"operations"</span> =&gt; <span style="color: #0000ff;">$operations</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$ds_service</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</pre>
</li>
</ol>
<p>That is it. You just exposed your query as a web service. The PHP script URL will be the endpoint URL for the web service.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/27/steps-to-convert-sql-query-to-a-data-service/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Use of SOAP Action with WSF/PHP</title>
		<link>http://www.dimuthu.org/blog/2008/11/25/the-use-of-soap-action-with-wsfphp/</link>
		<comments>http://www.dimuthu.org/blog/2008/11/25/the-use-of-soap-action-with-wsfphp/#comments</comments>
		<pubDate>Tue, 25 Nov 2008 15:05:23 +0000</pubDate>
		<dc:creator>dimuthu</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Tutorial/Guide]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>
		<category><![CDATA[wso2]]></category>
		<category><![CDATA[action]]></category>
		<category><![CDATA[soap 1.1]]></category>
		<category><![CDATA[soap 1.2]]></category>
		<category><![CDATA[SOAP action]]></category>

		<guid isPermaLink="false">http://www.dimuthu.org/?p=727</guid>
		<description><![CDATA[In SOAP 1.1, the SOAP action is mentioned as a compulsory HTTP header. In practice it was used to identify the operation for a given request which we identify by the term &#8216;dispatching operations&#8217;. As of SOAP 1.2, the SOAP action field became optional, and it was part of the content type header. In WSF/PHP, [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528">SOAP 1.1, the SOAP action</a> is mentioned as a compulsory HTTP header. In practice it was used to identify the operation for a given request which we identify by the term &#8216;dispatching operations&#8217;.<br />
As of <a href="http://www.w3.org/TR/soap12-part2/#ActionFeature">SOAP 1.2, the SOAP action field</a> became optional, and it was part of the content type header.</p>
<p>In <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a>, you can use the &#8220;action&#8221; property of WSMessage to set the  SOAP action in a request SOAP message.</p>
<pre class="php"><span style="color: #0000ff;">$requestPayloadString</span> = &lt;&lt;&lt;XML
&lt;ns1:echoString xmlns:ns1=<span style="color: #ff0000;">"http://wso2.org/wsfphp/samples"</span>&gt;
   &lt;text&gt;Hello World!&lt;/text&gt;
&lt;/ns1:echoString&gt;
XML;

<span style="color: #0000ff;">$client</span> = <span style="font-weight: bold; color: #000000;">new</span> WSClient<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span> <span style="color: #ff0000;">"to"</span> =&gt; <span style="color: #ff0000;">"http://localhost/samples/echo_service.php"</span> <span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$requestMessage</span> = <span style="font-weight: bold; color: #000000;">new</span> WSMessage<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$requestPayloadString</span>,
	    <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"action"</span> =&gt; <span style="color: #ff0000;">"http://localhost/samples/echo_service/echoString"</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$responseMessage</span> = <span style="color: #0000ff;">$client</span>-&gt;<span style="color: #006600;">request</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$requestMessage</span><span style="color: #66cc66;">)</span>;

<a href="http://www.php.net/printf"><span style="color: #000066;">printf</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"Response = %s &lt;br&gt;"</span>, <a href="http://www.php.net/htmlspecialchars"><span style="color: #000066;">htmlspecialchars</span></a><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$responseMessage</span>-&gt;<span style="color: #006600;">str</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p>WSF/PHP send SOAP 1.2 request by default. So the SOAP message HTTP headers for the above code would be like this,</p>
<pre>POST /samples/echo_service.php HTTP/1.1
User-Agent: Axis2C/1.5.0
Content-Length: 223
Content-Type: application/soap+xml;charset=UTF-8;action="http://localhost/samples/echo_service/echoString"
Host: 127.0.0.1</pre>
<p>Note that the SOAP  Action is sent in the Content-Type inside the optional action parameter.</p>
<p>If you set it to use SOAP 1.1 explicitly in the WSClient like this,</p>
<pre class="php"><span style="color: #0000ff;">$client</span> = <span style="font-weight: bold; color: #000000;">new</span> WSClient<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span> <span style="color: #ff0000;">"to"</span> =&gt; <span style="color: #ff0000;">"http://localhost/samples/echo_service.php"</span>,
                              <span style="color: #ff0000;">"useSOAP"</span> =&gt; <span style="color: #cc66cc;">1.1</span> <span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</pre>
<p>It would send the SOAP Action as a separate HTTP header,</p>
<pre>POST /samples/echo_service.php HTTP/1.1
User-Agent: Axis2C/1.5.0
SOAPAction: "http://localhost/samples/echo_service/echoString"
Content-Length: 225
Content-Type: text/xml;charset=UTF-8
Host: 127.0.0.1</pre>
<p>If you are using WSF/PHP in the server side, you don&#8217;t need to worry about the SOAP version as it will support both SOAP 1.1 and SOAP 1.2 automatically.<br />
Anyway you need to declared the actions to operations map, so WSF/PHP will be able to dispatch the SOAP request and direct the message to the correct operation.</p>
<pre class="php"><span style="font-weight: bold; color: #000000;">function</span> echoStringFunc<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$inMessage</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
    <span style="font-style: italic; color: #808080;">// logic of echoString operation</span>
<span style="color: #66cc66;">}</span>

<span style="font-weight: bold; color: #000000;">function</span> echoIntFunc<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$inMessage</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span>
    <span style="font-style: italic; color: #808080;">// logic of echoInt operation</span>
<span style="color: #66cc66;">}</span>

<span style="font-style: italic; color: #808080;">// we will take echoString and echoInt as tow operations</span>
<span style="color: #0000ff;">$operations</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"echoString"</span> =&gt; <span style="color: #ff0000;">"echoStringFunction"</span>,
                    <span style="color: #ff0000;">"echoInt"</span> =&gt; <span style="color: #ff0000;">"echoIntFunction"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// soap action to operation map</span>
<span style="color: #0000ff;">$actions</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"http://localhost/samples/echo_service/echoString"</span> =&gt; <span style="color: #ff0000;">"echoString"</span>,
                 <span style="color: #ff0000;">"http://localhost/samples/echo_service/echoInt"</span> =&gt; <span style="color: #ff0000;">"echoInt"</span><span style="color: #66cc66;">)</span>;

<span style="font-style: italic; color: #808080;">// creating the service with the operations and actions set</span>
<span style="color: #0000ff;">$service</span> = <span style="font-weight: bold; color: #000000;">new</span> WSService<span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">"operations"</span> =&gt; <span style="color: #0000ff;">$operations</span>,
                               <span style="color: #ff0000;">"actions"</span> =&gt; <span style="color: #0000ff;">$actions</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;

<span style="color: #0000ff;">$service</span>-&gt;<span style="color: #006600;">reply</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</pre>
<p>So whenever a SOAP request message hit this script, it will check the SOAPAction HTTP header if it is a SOAP 1.1 message, or the action parameter in the Content-Type HTTP header if it is 1.2, then try to find the function mapped with that action from the actions map.<br />
Anyway if the SOAP action is not set in the request message WSF/PHP will try to dispatch the message with other methods like body based dispatching, WS-Addressing based dispatching which are transport protocol independent dispatching mechanisms.</p>
<p>Anyway since most of the cases SOAP is used on top of HTTP, it is really common SOAP messages are dispatched using the SOAP action which is no doubt a very easy and efficient way of dispatching.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dimuthu.org/blog/2008/11/25/the-use-of-soap-action-with-wsfphp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

