<?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>Engwar &#187; php</title>
	<atom:link href="http://engwar.com/tags/php/feed" rel="self" type="application/rss+xml" />
	<link>http://engwar.com</link>
	<description>Chintana Wilamuna&#039;s weblog</description>
	<lastBuildDate>Sat, 03 Jul 2010 08:48:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Using PHP with SQL Azure</title>
		<link>http://engwar.com/post/191</link>
		<comments>http://engwar.com/post/191#comments</comments>
		<pubDate>Tue, 01 Dec 2009 12:23:11 +0000</pubDate>
		<dc:creator>Chintana</dc:creator>
				<category><![CDATA[azure]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[sqlazure]]></category>

		<guid isPermaLink="false">http://engwar.com/?p=191</guid>
		<description><![CDATA[SQL Azure is a wonderful service running the database in the cloud. This post summarizes the gotchas that you might wanna lookout for when trying to connect your PHP applications to talk to SQL Azure. The default driver php_mssql.dll doesn&#8217;t work with SQL Azure. The Internets say that support for php_mssql is dropped from PHP [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sql.azure.com/">SQL Azure</a> is a wonderful service running the database in the cloud. This post summarizes the gotchas that you might wanna lookout for when trying to connect your PHP applications to talk to SQL Azure.</p>
<ol>
<li>The default driver php_mssql.dll doesn&#8217;t work with SQL Azure. The Internets say that support for php_mssql is dropped from PHP 5.3. I have PHP 5.2.10 and was a bit surprised when I can connect to any SQL server instance in the network (2005/2008) using php_mssql but not to SQL Azure. The all too generic Unable to connect to server message was also not helping. You have to use the <a href="http://blogs.msdn.com/sqlphp/archive/2009/10/07/sql-server-driver-for-php-1-1-is-now-available.aspx">new MSSQL driver for PHP</a>.</li>
<li>After you download and unzip the new driver you&#8217;ll see a set of DLLs with different versions. For PHP 5.2.10 you have to use php_sqlsrv_52_ts_vc6.dll. Rename it as php_sqlsrv.dll and copy it to the &lt;PHP&gt;\ext directory.</li>
<li>Then add <code>extension=php_sqlsrv.dll</code> to your php.ini</li>
<li>After that, you have to connect to the SQL Azure database with MultipleActiveResultSets option turned off.
<pre>
sqlsrv_connect( "server_name",
    array( "MultipleActiveResultSets" => 0, ... ) );
</pre>
</li>
</ol>
<p>Voila! Now you&#8217;re all set to pull data from the clouds!</p>
]]></content:encoded>
			<wfw:commentRss>http://engwar.com/post/191/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RESTful PHP Web Services</title>
		<link>http://engwar.com/post/75</link>
		<comments>http://engwar.com/post/75#comments</comments>
		<pubDate>Sun, 22 Feb 2009 07:31:54 +0000</pubDate>
		<dc:creator>Chintana</dc:creator>
				<category><![CDATA[books]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>

		<guid isPermaLink="false">http://engwar.com/?p=75</guid>
		<description><![CDATA[If you&#8217;ve read the architectural notes about RESTful applications and want to get your hands dirty writing one quickly, RESTful PHP Web Services by Samisa Abeysinghe is a book you should read. It starts with an introduction to what REST is and surrounding technologies. Since many web applications today expose their functions as RESTful APIs, [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve read the architectural notes about RESTful applications and want to get your hands dirty writing one quickly, <a href="http://www.packtpub.com/restful-php-web-services/book">RESTful PHP Web Services</a> by Samisa Abeysinghe is a book you should read. It starts with an introduction to what REST is and surrounding technologies. Since many web applications today expose their functions as RESTful APIs, you&#8217;ll be better prepared to play around with these after reading this book. Also a simple application that explains all the necessary functions for developing a RESTful application is discussed.</p>
<p>Introduction gives the reader a head start about what REST is all about and tools needed to play with RESTful web services. Then PHP libraries and function used for talking to a REST service is explained. How <a href="http://curl.haxx.se/">CURL</a> is used to send requests with various HTTP verbs such as GET, POST, PUT, DELETE are explained with examples. After getting an XML response from a service, PHP libraries for manipulating XML and extracting parts of data you want is illustrated with samples. One could directly copy and paste these codes and try it out as they read along. Then the author goes on to explain how to use <a href="http://flickr.com/">Flickr</a> with PHP using CURL. If you&#8217;ve been using a high level library that insulate the lower level details, this example shows some of the basic API calls and how to use them.</p>
<p>After explaining a mashup of BBC news feed and Yahoo search API, author explains how to design RESTful services. This is carried out along with the simple but complete example of a library system. How to provide a service as well as consuming that using PHP and CURL is explained with complete code samples. Then he explains how to design the same thing using the <a href="http://framework.zend.com/">Zend Framework</a>.</p>
<p>The book concludes with a chapter dedicated to debugging REST web services. Using the TCPMon tool to capture messages and look for possible errors. The chapter ends with a set of best practices that everyone should be aware of if you do any programming with REST web services. The book also mentions <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> as an advanced framework providing many more functionality amidst of acting as a REST framework. I highly recommend this book if you&#8217;re a PHP programmer waiting to get your hands dirty designing RESTful applications. To whet your appetite here&#8217;s a <a href="http://engwar.com/wp-content/uploads/2009/02/restful-php-webservices_sample-chapter.pdf">sample chapter from the book about designing and implementing resource oriented clients</a>. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://engwar.com/post/75/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Enterprise PHP</title>
		<link>http://engwar.com/post/53</link>
		<comments>http://engwar.com/post/53#comments</comments>
		<pubDate>Mon, 22 Sep 2008 03:39:44 +0000</pubDate>
		<dc:creator>Chintana</dc:creator>
				<category><![CDATA[eai]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[soa]]></category>
		<category><![CDATA[web services]]></category>
		<category><![CDATA[wsf/php]]></category>

		<guid isPermaLink="false">http://engwar.com/?p=53</guid>
		<description><![CDATA[Samisa has written a nice post about using PHP in the enterprise. A commenter there argues that he don&#8217;t use PHP because it&#8217;s a dynamically typed language. It&#8217;s somewhat true that if you&#8217;re coming from a statically typed language background you&#8217;re stormed with so many questions and wonder possible nightmares of using one. Once you [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://samisa-abeysinghe.blogspot.com/2008/09/php-for-enterprise.html">Samisa has written a nice post about using PHP in the enterprise</a>. A commenter there argues that he don&#8217;t use PHP because it&#8217;s a dynamically typed language. It&#8217;s somewhat true that if you&#8217;re coming from a statically typed language background you&#8217;re stormed with so many questions and wonder possible nightmares of using one. Once you start learning a language and understand how programs are suppose to be written in that language most of these problems go away.</p>
<p>For all these years, it has only been Java/.Net programmers who has been enjoying the luxury of service oriented architectures. These folks understand the value of building a business functionality as a service or exposing an existing functionality as a service. PHP programmers have been building their web based programs happily without having to know what services mean. People in the PHP community has tried to bring Web services into the language with varying degrees of success. These are very courages and thoughtful efforts. But if you analyze them objectively you&#8217;ll see that many of these libraries doesn&#8217;t contain that much of features in order to build/integrate an application with an existing enterprise app.</p>
<p>What <a href="http://wso2.org/projects/wsf/php">WSF/PHP</a> has done is lower the bar of building PHP applications that can fit with existing applications in an enterprise written in Java/.Net or whatever the language that might be. Also, it has enabled ability to integrate existing PHP applications to your other enterprise applications.</p>
<p>One strong reason companies have embraced developing applications in Java is that so their data will not be isolated from rest of the enterprise data. In the past having a PHP application inside your company might have been frowned upon because it doesn&#8217;t make sense to have information which is isolated from all the other applications in the company. This is why most organizations invest in an ERP for example. But now, this has become a non issue. If you&#8217;re using open standards inside your enterprise to communicate/integrate applications, using WSF/PHP, you can integrate or extend services seamlessly with rest of your enterprise services. </p>
]]></content:encoded>
			<wfw:commentRss>http://engwar.com/post/53/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Drupal, amelioratory management</title>
		<link>http://engwar.com/post/47</link>
		<comments>http://engwar.com/post/47#comments</comments>
		<pubDate>Sat, 23 Aug 2008 03:48:05 +0000</pubDate>
		<dc:creator>Chintana</dc:creator>
				<category><![CDATA[drupal]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://engwar.com/?p=47</guid>
		<description><![CDATA[I&#8217;m going to take Drupal as an example during this post and outline some of the challenges of working on it with a loosely knit team. One major problem with PHP based content management systems is that it&#8217;s PHP. So, anyone who have taken the time to stare at some code snippets could modify, say, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m going to take <a href="http://drupal.org/">Drupal</a> as an example during this post and outline some of the challenges of working on it with a loosely knit team.  One major problem with PHP based content management systems is that it&#8217;s PHP.  So, anyone who have taken the time to stare at some code snippets could modify, say, the user module (in Drupal) and get his changes displayed (assuming that&#8217;s what he wanted in the first place).  As a side note, <a href="http://www.php.net/manual/en/">PHP Manual</a> is all you need to learn about PHP.  This was a much criticized fact for Ruby, lack of freely accessible up-to-date documentation.  Although situation is improving as the <a href="http://ruby-doc.org/">ruby-doc</a> project gained more momentum. Any &#8220;teach yourself how to clean dog poop in 24 hours&#8221; guides are useless because it&#8217;ll take <a href="http://www.norvig.com/21-days.html">10 years to learn howto program</a> effectively.</p>
<p>Coming back to Drupal, this issue of having the freedom to modify anything &#8216;cos it&#8217;s all PHP should really not be an issue but experience suggest otherwise.  Having restricted access to Drupal core files is also of limited success. Remember, I&#8217;m not talking from an outsiders perspective where you worry about world readable files and whatnot, this is from the developer perspective who has full control over making a code level change. A set of people maintaining the site doing continuous modifications.</p>
<p>If you&#8217;re just running Drupal as a blog and you&#8217;re the only one who makes changes to it, then there are no issues. In a team environment sometimes you assume that something like a change to a core file should not be done unless you have 1) googled 2) RTFM (thrice) and there&#8217;s no other way to do it, but surprisingly people overlook this fact and do change the stuff that should not be changed. Usually these kind of shit happens when you cut your software engineering lectures and go collecting meadow muffins on perfectly bright and sunny days. </p>
<p>Close examination suggest legitimate reasons such as,</p>
<ol>
<li>It&#8217;s easy to customize, say, <code>include/common.inc</code> rather than reading the API doc, which is comparatively harder and takes more time</li>
<li>Naming conventions. <code>common.inc</code>. &#8220;I need to display the top most blah blah blah nodes on these set of pages, it&#8217;s a common feature to all these so <code>common.inc</code> is the right place to do it&#8221;.</li>
<li>You do need to get something displayed, quickly, you know it&#8217;s not the right way to do it but since time is more important you decide to change a line in a core module which is trivial.</li>
</ol>
<p>All goes well for a couple of years until someone else takes over and use the universal language to communicate with your entire genealogy.</p>
<p>Those 10 second hack jobs will stack up with time and by the time shit hits the fan, no amount of version control could save you. Problems arise when you have to update your CMS. Files such as <code>common.inc</code> belongs to the Drupal core and will be updated. So if you have modifications in those files you now have to get those to the system. If you&#8217;re really unlucky and the API has changed now you have to substitute the new functions. This will become tedious when you have to go through each and every file to see what has been added/modified. Things get more vexing if you have nodes embedded with PHP code. These are nodes with Input type PHP.  If the API has changed now you have to go through those pages and see what breaks.</p>
<p>So what are the possible solutions for this mussed up state of affairs?</p>
<ol>
<li>Making it hard to modify the core files which will be replaced during an upgrade.</li>
<li>Enforce an internal policy regarding the modifications so that changes happen in either the theme used or in a separate module.</li>
</ol>
<p>Making everyone aware of the extension mechanisms available and doing changes in a disciplined manner will save you when you have to upgrade. Also this will make the life of the <a href="http://c2.com/cgi/wiki?MaintenanceProgrammer">maintenance programmer</a> easier. This does have one drawback. Turnaround times for features/changes will now take a bit more time than earlier but the big upside is the whole thing could be rapidly updated (if there&#8217;s a security vulnerability or a newer version have a killer feature, makes it faster etc&#8230;) and someone else could take over without much effort.</p>
]]></content:encoded>
			<wfw:commentRss>http://engwar.com/post/47/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fiddling with drupal forms</title>
		<link>http://engwar.com/post/46</link>
		<comments>http://engwar.com/post/46#comments</comments>
		<pubDate>Fri, 22 Aug 2008 04:00:06 +0000</pubDate>
		<dc:creator>Chintana</dc:creator>
				<category><![CDATA[drupal]]></category>
		<category><![CDATA[oxygentank]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://engwar.com/?p=46</guid>
		<description><![CDATA[This will show some of the neat API calls Drupal provides which you could use to do almost anything. OxygenTank, the developer portal related to WSO2 products runs on Drupal. The code examples in this post are extracted from a soon to be implemented module which will alter the way you download products. Everything you [...]]]></description>
			<content:encoded><![CDATA[<p>This will show some of the neat API calls Drupal provides which you could use to do almost anything.  <a href="http://wso2.org/">OxygenTank</a>, the developer portal related to <a href="http://wso2.org/downloads">WSO2 products</a> runs on <a href="http://drupal.org/">Drupal</a>.  The code examples in this post are extracted from a soon to be implemented module which will alter the way you download products. Everything you need to know about the <a href="http://api.drupal.org/">Drupal API is nicely documented</a>.</p>
<p>Forms are defined as PHP arrays,</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$form</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'noreg'</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;">'#type'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'checkboxes'</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'#title'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">&quot;Reason not to register&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'#options'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$reasons</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'#default_value'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">'#validate'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'fizzed_up_validator'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>When the above code fragment gets rendered into HTML it&#8217;ll be a list of checkboxes with the items in <code>$reasons</code>. Also note that we&#8217;re passing a custom validation function. Inside your custom validation function you could perform all the checking and if there&#8217;s an error condition you could say,</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">form_set_error<span style="color: #009900;">&#40;</span><span style="color: #000088;">$form</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>which will display an error message and redirects users back to the form. <code>$form</code> is a parameter your validation function takes. Forms API is well documented with examples.</p>
<p>There&#8217;s this need to add the user to a particular role depending on from where the user come to the download page. This should be done in the registration phase. That&#8217;s trivial to do with Drupal. You could get this &#8220;event&#8221; where the user submitted details has passed all the validation logic and about to be inserted into the database, at that time you have to fetch the role info from the DB and insert stuff to <code>users_roles</code> table. Oh, and the redirection part. When the form is successfully submitted (meaning user got registered) you could redirect the user to anywhere. All the API and the things you could do with it is extremely well thought out and nice to play with. To get this registration form, all I had to do was hide some attributes before the form gets rendered. For example look at the standard <a href="http://wso2.org/user/register">registration page</a>. Embedded registration form of the newly designed page had to contain only the mandatory fields. There was no need to display rest of the stuff. So, what I had to do was in <code><a href="http://api.drupal.org/api/function/hook_form_alter/6">hook_form_alter</a></code> unset the relevant <code>$form['elems']</code>. Had to define a session variable to detect we&#8217;re coming from the right page, otherwise the all the registration form instances will be changed. After that display the form,</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">drupal_get_form<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'user_register'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>voila! Now you have a customized registration form. The cool thing is all the validation stuff defined for the registration form will work and you don&#8217;t have to do anything extra.</p>
<p>A slightly less documented API call that we use is <code><a href="http://api.drupal.org/api/function/user_external_load/6">user_external_load</a></code>. This&#8217;ll load a given user&#8217;s details into the current session so that the user will be logged into the system. To pull this off successfully there needs to be an entry in the <code>authmap</code> table as the function implementation shows. I&#8217;ve not been able to find a way one could insert a record to this table via the admin screens.</p>
]]></content:encoded>
			<wfw:commentRss>http://engwar.com/post/46/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
