<?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>Connecting the dots... &#187; php</title>
	<atom:link href="http://blog.rajatpandit.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.rajatpandit.com</link>
	<description>Thoughts on Web Development, Infrastructure and Application Scalability</description>
	<lastBuildDate>Thu, 29 Dec 2011 13:21:11 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Xdebug &#8211; Remote Debugging</title>
		<link>http://blog.rajatpandit.com/2010/04/30/xdebug-remote-debugging/</link>
		<comments>http://blog.rajatpandit.com/2010/04/30/xdebug-remote-debugging/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 01:56:47 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[remote debugging]]></category>
		<category><![CDATA[xdebug]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=503</guid>
		<description><![CDATA[As a follow up from my last post Xdebug – Installation and customization this post is about configuring xdebug and a php editor (eclipse PDT) in this case to be...]]></description>
			<content:encoded><![CDATA[<p>As a follow up from my last post<a href="http://blog.rajatpandit.com/2010/04/30/xdebug-installation-and-customization/"> <a href="http://xdebug.org/">Xdebug</a> – Installation and customization</a> this post is about configuring <a href="http://xdebug.org/">xdebug</a> and a <a href="http://php.net">php</a> editor (eclipse PDT) in this case to be able to do interactive debugging. Having worked as a Java Developer for quite some time, this was always something that I found missing in php or maybe I didn&#8217;t look hard enough. I have been using Xdebug for debugging code for a while now and it has actually affected my productivity quite dramatically. I am documenting the process of setting this up for anyone who might find it useful.</p>
<p>So just to give you a background of what really happens when you are using Xdebug for debugging. Loading xdebug as a zend module allows it to hook into the execution of php scripts. This means that you can really send the module instructions to pause and resume the execution. Also since it hooks into the execution it has access to all the variables at the time of execution which obviously is very useful for debugging purposes.<br />
Xdebug is called a remote-debugger because the client doesn&#8217;t have to run on the same server as the webserver (or php instance running the script). The client and server communicate via their own protocol which is either <code><a href="http://davis.lbl.gov/Manuals/GDB/gdb_31.html">GDB</a></code> or <code><a href="http://xdebug.org/docs-dbgp.php">DBGp</a></code>. We will be using DBGp since Eclipse PDT supports it out of the box. To start the session the script needs to be called with the parameter <code>XDEBUG_SESSION_START</code> and similarly to stop it, it needs to be called again but with the argument <code>XDEBUG_SESSION_STOP</code>. There are <a href="https://addons.mozilla.org/en-US/firefox/search?q=xdebug&#038;cat=all">firefox extensions</a> that will do that for you so its worth looking into it, however Eclipse PDT (and possibly Netbeans) does that for you out of the box. Once triggered the client/server communicate via the chosen protocol and you can see your values in the debug perspective.</p>
<p>So lets start off by configuring the server side of things. Lets have a quick look at some of the ini settings that I had show in my <a href="http://blog.rajatpandit.com/2010/04/30/xdebug-installation-and-customization/">previous post</a> and had mentioned they will be covered in the next post.</p>
<pre class="brush: bash; title: ; notranslate">
xdebug.remote_enable=On
xdebug.remote_host=&quot;172.16.110.1&quot;
xdebug.remote_port=9000
xdebug.remote_handler=&quot;dbgp&quot;
</pre>
<p>Lets walk though the set of parameters required:</p>
<ul>
<li><strong>xdebug.remote_enable:</strong> This enables the remote debugging mode. This will enable triggering of debugging by passing the above mentioned arguments</li>
<li><strong>xdebug.remote_host:</strong> You can specify the client hostname or IP address. This will get the server to connect to this client to pass the debugging information. This can be handy when your server is on one box, your scripts are running on another one (via selenium for instance) and your debugging tool is running on another box. This might look like a limiting feature that it only listens to the IP address mentioned in the config. However you configure xdebug to be able to start debugging from a request coming from any other host by setting <code>xdebug.remote_connect_back</code> to 1. This will make xdebug use <code>$_SERVER['REMOTE_ADDR']</code> find out where the request came from and talk to the client. This obviously means, DON&#8217;T TURN THIS ON IN PRODUCTION.</li>
<li><strong>xdebug.remote_port:</strong> This is the port at which xdebug tries to connect to the remote host. 9000 i usually the default value for most clients so its best not to change this unless you have to get around some crazy IT firewall rules.</li>
<li><strong>xdebug.remote_handler:</strong> Is to define the protocol to use. The default is <code>dbgp</code> so you can get away without having to make this entry unless you want to change it to the older protocol for some reason</li>
</ul>
<p>That&#8217;s pretty much all you need to do from the server side of things. Obviously if you are using apache, then you need to reload the configuration so that the ini files get re-read again with the new settings:</p>
<pre class="brush: bash; title: ; notranslate">
$ sudo /etc/init.d/apache reload
</pre>
<p>The next step is to configure Eclipse to debug. Rather than explaining it, I am listing screen-shots of configuration from my eclipse editor. My current eclipse build is: <code>Build id: 20090920-1017</code>. Click on the individual images to see their bigger versions.</p>
<div id="attachment_506" class="wp-caption aligncenter" style="width: 852px"><a href="http://blog.rajatpandit.com/wp-content/uploads/2010/04/default-browser-settings.png"><img src="http://blog.rajatpandit.com/wp-content/uploads/2010/04/default-browser-settings.png" alt="" title="" width="842" height="646" class="size-full wp-image-506" /></a><p class="wp-caption-text">Setting default browser to System default rather than the internal browser as part of Eclipse.</p></div>
<div id="attachment_510" class="wp-caption aligncenter" style="width: 468px"><a href="http://blog.rajatpandit.com/wp-content/uploads/2010/04/xdebug-settings.png"><img src="http://blog.rajatpandit.com/wp-content/uploads/2010/04/xdebug-settings.png" alt="" title="" width="458" height="628" class="size-full wp-image-510" /></a><p class="wp-caption-text">Under PHP->Debug -> Select XDebug and click configure. Showing the options for xdebug</p></div>
<div id="attachment_508" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.rajatpandit.com/wp-content/uploads/2010/04/edit-server-information.png"><img src="http://blog.rajatpandit.com/wp-content/uploads/2010/04/edit-server-information-300x196.png" alt="" title="" width="300" height="196" class="size-medium wp-image-508" /></a><p class="wp-caption-text">Editing Server information. This server is where the xdebug server is present. This is also the place where you configure your script mappings etc.</p></div>
<div id="attachment_509" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.rajatpandit.com/wp-content/uploads/2010/04/new-debug-configuration.png"><img src="http://blog.rajatpandit.com/wp-content/uploads/2010/04/new-debug-configuration-300x213.png" alt="" title="" width="300" height="213" class="size-medium wp-image-509" /></a><p class="wp-caption-text">Setting up a new debug configuration</p></div>
<div id="attachment_507" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.rajatpandit.com/wp-content/uploads/2010/04/eclipse-in-debug-prespective.png"><img src="http://blog.rajatpandit.com/wp-content/uploads/2010/04/eclipse-in-debug-prespective-300x189.png" alt="" title="" width="300" height="189" class="size-medium wp-image-507" /></a><p class="wp-caption-text">Script running in the debug prespective in eclipse. Notice the variables on the top right showing the values at its current state.</p></div>
<div id="in_post_ad_bottom_1" style="clear:both;margin:0;padding:0;"><div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-bp */
google_ad_slot = "7787511801";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-BP-1 */
google_ad_slot = "9111022353";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2010/04/30/xdebug-remote-debugging/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Writing a php command line based app using Console_CommandLine</title>
		<link>http://blog.rajatpandit.com/2009/10/17/writing-a-php-command-line-based-app-using-console_commandline/</link>
		<comments>http://blog.rajatpandit.com/2009/10/17/writing-a-php-command-line-based-app-using-console_commandline/#comments</comments>
		<pubDate>Sat, 17 Oct 2009 12:40:05 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[Console_CommandLine]]></category>
		<category><![CDATA[pear]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=358</guid>
		<description><![CDATA[I am currently writing a PHP app which had to have a command line interface. I came across this excellent library in PEAR Console_CommandLine. Its core functionality is very useful...]]></description>
			<content:encoded><![CDATA[<p>I am currently writing a <a href="http://php.net">PHP</a> app which had to have a command line interface. I came across this excellent library in <a href="http://pear.php.net">PEAR</a> <a href="http://pear.php.net/manual/en/package.console.console-commandline.php">Console_CommandLine</a>. Its core functionality is very useful out of the box and in case you need to do something really fancy, there is nothing stopping you from extending it further. </p>
<p>Here is a quick example for anyone interested in getting up and running with it.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
require_once 'Console/CommandLine.php';

$parser = new Console_CommandLine();
$parser-&gt;description = 'A fantastic command line program that does nothing.';
$parser-&gt;version = '1.5.0';
$parser-&gt;addOption('filename', array(
    'short_name'  =&gt; '-f',
    'long_name'   =&gt; '--file',
    'description' =&gt; 'write report to FILE',
    'help_name'   =&gt; 'FILE',
    'action'      =&gt; 'StoreString'
));
$parser-&gt;addOption('quiet', array(
    'short_name'  =&gt; '-q',
    'long_name'   =&gt; '--quiet',
    'description' =&gt; &quot;don't print status messages to stdout&quot;,
    'action'      =&gt; 'StoreTrue'
));
try {
    $result = $parser-&gt;parse();
    // do something with the result object
    print_r($result-&gt;options);
    print_r($result-&gt;args);
} catch (Exception $exc) {
    $parser-&gt;displayError($exc-&gt;getMessage());
}
</pre>
<p>gives the output for <code>yourscript -help</code></p>
<pre class="brush: bash; title: ; notranslate">
A fantastic command line program that does nothing.

Usage:
  tmp.php [options]

Options:
  -f FILE, --file=FILE  write report to FILE
  -q, --quiet           don't print status messages to stdout
  -h, --help            show this help message and exit
  --version             show the program version and exit
</pre>
<p>Details for options/configuration:<a href="http://pear.php.net/manual/en/package.console.console-commandline.options.php"> http://pear.php.net/manual/en/package.console.console-commandline.options.php</a></p>
<p>Details for command line arguments: <a href="http://pear.php.net/manual/en/package.console.console-commandline.arguments.php">http://pear.php.net/manual/en/package.console.console-commandline.arguments.php</a></p>
<p>Details for extending lib: <a href="http://pear.php.net/manual/en/package.console.console-commandline.extending.php">http://pear.php.net/manual/en/package.console.console-commandline.extending.php</a></p>
<div id="in_post_ad_bottom_1" style="clear:both;margin:0;padding:0;"><div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-bp */
google_ad_slot = "7787511801";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-BP-1 */
google_ad_slot = "9111022353";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2009/10/17/writing-a-php-command-line-based-app-using-console_commandline/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Doctrine_Parser_Exception] Fail-some error message!</title>
		<link>http://blog.rajatpandit.com/2009/08/23/doctrine_parser_exception-fail-some-error-message/</link>
		<comments>http://blog.rajatpandit.com/2009/08/23/doctrine_parser_exception-fail-some-error-message/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 17:50:26 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[jwage]]></category>
		<category><![CDATA[orm]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=369</guid>
		<description><![CDATA[If your precious evening hacking time has been wasted by this useless error message: Then look no further, this was the oddest error message which caused errors inconsistently when generating...]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.doctrine-project.org/"><img src="http://blog.rajatpandit.com/wp-content/uploads/2009/08/doctrine-orm-php5.png" alt="doctrine" title="doctrine" width="191" height="53" class="alignright size-full wp-image-370" /></a><br />
If your precious evening hacking time has been wasted by this useless error message:</p>
<pre class="brush: bash; title: ; notranslate">
rp@devbox:trunk$ php symfony --trace doctrine:build-all-reload --no-confirmation
&gt;&gt; doctrine  dropping databases
&gt;&gt; doctrine  Successfully dropped database f...octrine&quot; named &quot;secret_project&quot;
&gt;&gt; doctrine  creating databases
&gt;&gt; doctrine  Successfully created database f...octrine&quot; named &quot;secret_project&quot;
&gt;&gt; doctrine  generating model classes

  [Doctrine_Parser_Exception]
  Unable to parse string: Unable to parse line 0 (  

Exception trace:
  at ...
....
</pre>
<p>Then look no further, this was the oddest error message which caused errors inconsistently when generating models or updating the schema files. It turned out that the error was due to </p>
<ul>
<li>vim swap files</li>
<li>osx ._ files</li>
</ul>
<p>The parser would pick up all the files even if it started with a . (dot) which then borks of-course coz it wasn&#8217;t in the format it would expect it to be in</p>
<p>What would have been useful would be to have more meaningful error message like full path+file name and also the parser shouldnt pickup . (dot) files in the first place, dont see why a developer would want to keep his config files starting with a . (dot) unless its a .htaccess file.</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin:0;padding:0;"><div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-bp */
google_ad_slot = "7787511801";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-BP-1 */
google_ad_slot = "9111022353";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2009/08/23/doctrine_parser_exception-fail-some-error-message/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Enabling HTTPS support in curl installed through MacPorts on OSX</title>
		<link>http://blog.rajatpandit.com/2009/03/31/enabling-https-support-in-curl-installed-through-macports-on-osx/</link>
		<comments>http://blog.rajatpandit.com/2009/03/31/enabling-https-support-in-curl-installed-through-macports-on-osx/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 22:27:40 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Clean]]></category>
		<category><![CDATA[dependencies]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[protocol]]></category>
		<category><![CDATA[variants]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=250</guid>
		<description><![CDATA[While doing development just noticed that if you have installed php with curl support using macports it does&#8217;nt install ssl support in curl by default which is quite frustrating. Especially...]]></description>
			<content:encoded><![CDATA[<p>While doing development just noticed that if you have installed php with curl support using macports it does&#8217;nt install ssl support in curl by default which is quite frustrating. Especially I just spent 30mins of my life trying to debugging what had gone wrong.</p>
<p>This is what you would get if you have a similar problem:</p>
<pre class="brush: bash; title: ; notranslate">
% curl -k https://www.yahoo.com
curl: (1) Protocol https not supported or disabled in libcurl
</pre>
<p>The problem is that you would usually have something that depends on curl so you cant install the version of curl with its variant straightaway, so you will first need to remove the dependent first, then remove curl and clean up the install and then finally install curl with its ssl variant followed by its dependents.</p>
<p>The steps are something like this:</p>
<pre class="brush: bash; title: ; notranslate">
busybox:web rp$ sudo port uninstall curl @7.19.3_0 curl @7.19.3_0+ssl
---&gt;  Unable to uninstall curl 7.19.3_0, the following ports depend on it:
---&gt;  	php5
Error: port uninstall failed: Please uninstall the ports that depend on curl first.
busybox:web rp$ sudo port uninstall curl @7.19.3_0 curl @7.19.3_0+ssl
busybox:web rp$ sudo port uninstall php5
---&gt;  Deactivating php5 @5.2.9_0+apache2+macosx+mysql5+pear+sqlite
---&gt;  Uninstalling php5 @5.2.9_0+apache2+macosx+mysql5+pear+sqlite
busybox:web rp$ sudo port uninstall curl @7.19.3_0 curl @7.19.3_0+ssl
---&gt;  Deactivating curl @7.19.3_0
---&gt;  Uninstalling curl @7.19.3_0
---&gt;  Uninstalling curl @7.19.3_0+ssl
busybox:web rp$ sudo port install php5 @5.2.9_0+apache2+macosx+mysql5+pear+sqlite
Error: Requested variants do not match original selection.
Please perform 'port clean curl' or specify the force option.
Error: The following dependencies failed to build: curl
Error: Status 1 encountered during processing.
busybox:web rp$ sudo port clean curl
---&gt;  Cleaning curl
busybox:web rp$ sudo port clean php5
---&gt;  Cleaning php5
busybox:web rp$ sudo port clean php5
---&gt;  Cleaning php5
busybox:web rp$ sudo port clean curl
---&gt;  Cleaning curl
busybox:web rp$ sudo port clean php5
busybox:web rp$ sudo port install curl +ssl
---&gt;  Fetching curl
---&gt;  Verifying checksum(s) for curl
---&gt;  Extracting curl
---&gt;  Configuring curl
---&gt;  Building curl
---&gt;  Staging curl into destroot
---&gt;  Installing curl @7.19.3_0+ssl
---&gt;  Activating curl @7.19.3_0+ssl
---&gt;  Cleaning curl
busybox:web rp$ sudo port install php5 @5.2.9_0+apache2+macosx+mysql5+pear+sqlite
---&gt;  Fetching php5
---&gt;  Verifying checksum(s) for php5
---&gt;  Extracting php5
---&gt;  Applying patches to php5
---&gt;  Configuring php5
---&gt;  Building php5
---&gt;  Staging php5 into destroot
Warning: php5 requests to install files outside the common directory structure!
---&gt;  Installing php5 @5.2.9_0+apache2+macosx+mysql5+pear+sqlite

If this is your first install, you might want
cd /opt/local/apache2/modules
/opt/local/apache2/bin/apxs -a -e -n &quot;php5&quot; libphp5.so

* copy  /opt/local/etc/php.ini-dist to  /opt/local/etc/php.ini
---&gt;  Activating php5 @5.2.9_0+apache2+macosx+mysql5+pear+sqlite
---&gt;  Cleaning php5
</pre>
<div id="in_post_ad_bottom_1" style="clear:both;margin:0;padding:0;"><div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-bp */
google_ad_slot = "7787511801";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-BP-1 */
google_ad_slot = "9111022353";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2009/03/31/enabling-https-support-in-curl-installed-through-macports-on-osx/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>using svn for development in symfony</title>
		<link>http://blog.rajatpandit.com/2009/02/08/using-svn-for-development-in-symfony/</link>
		<comments>http://blog.rajatpandit.com/2009/02/08/using-svn-for-development-in-symfony/#comments</comments>
		<pubDate>Sun, 08 Feb 2009 15:36:14 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[bug fixes]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[directory structure]]></category>
		<category><![CDATA[dramatic changes]]></category>
		<category><![CDATA[empty directory]]></category>
		<category><![CDATA[initial directory]]></category>
		<category><![CDATA[iteration]]></category>
		<category><![CDATA[nature of the product]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[product development cycle]]></category>
		<category><![CDATA[repos]]></category>
		<category><![CDATA[secret project]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=204</guid>
		<description><![CDATA[The recent project that I am working on for a client has taught me more about svn than I ever did because of the complex nature of the product. It...]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.rajatpandit.com/wp-content/uploads/2009/02/tdgts_pile.jpg" alt="Symfony" title="Symfony" width="300" height="410" class="alignright size-full wp-image-206" />The recent project that I am working on for a client has taught me more about <code>svn</code> than I ever did because of the complex nature of the product. It has been going through a proper product development cycle which involves quick iteration of features and sometimes, such dramatic changes that can make the entire code base unstable for weeks until the change is brought about.<br />
In addition to that, I have always preferred to work with the latest version of symfony so that I am always up-to-date in terms of bug fixes and manage to provide the very best of code base.</p>
<p>I trolled through the <code>svn</code> manuals and <a href="http://stereointeractive.com/blog/2008/12/10/starting-a-new-symfony-project/">some really interesting blog posts</a> and summarizing the steps that I took to put my code base back into control. Its rather unusual that none of the steps below are anything special its just that I hadnt had to work on a situation where I had to work on a feature which might or might not see the daylight of being pushed to production. </p>
<p>So the first thing to do was to create the trunk, branches and tags directory. </p>
<pre class="brush: bash; title: ; notranslate">
$ mkdir ~/websites/secret-project/trunk \
            ~/websites/secret-project/branches \
            ~/websites/secret-project/tags
</pre>
<p>I now use <a href="http://dreamhost.com">dreamhost</a> for my svn but you can replace this with any other repo (local or remote) to manage your code. So I would start by creating the initial directory structure in the repo.</p>
<pre class="brush: bash; title: ; notranslate">
$ svn import -m 'Importing the initial directory structure' \
                http://svn.rajatpandit.com/secret-project/trunk \
                http://svn.rajatpandit.com/secret-project/branches \

http://svn.rajatpandit.com/secret-project/tags
</pre>
<p>Now checking out the empty directory locally to setup the local directories we created locally.</p>
<pre class="brush: bash; title: ; notranslate">
$ svn co http://svn.rajatpandit.com/secret-project/trunk \
               ~/websites/secret-project/trunk
</pre>
<p>The next step is to ensure that you are always using the most recent version of symfony. I like this feature about svn. You can have multiple directories pointing to multiple repos, that we can always ensure that your project can benefit from the most recent versions. We start that by setting up the lib/symfony and marking that as having an external repo.</p>
<pre class="brush: bash; title: ; notranslate">
$ cd  ~/websites/secret-project/
$ mkdir trunk/lib
$ mkdir trunk/lib/vendor
$ svn propedit svn:externals lib/vendor
symfony http://svn.symfony-project.com/tags/RELEASE_1_2_4/
</pre>
<p>(1.2.4 being the most recent release at the time of writing this post)<br />
This is a good time to commit this to the svn and get the latest code.</p>
<pre class="brush: bash; title: ; notranslate">
$ svn ci -m 'updating symfony to 1.2.4'
$ svn update lib/vendor
</pre>
<p>With the most recent codebase available in the vendors directory, now is a good time to do any sanity checks if you fancy.</p>
<pre class="brush: bash; title: ; notranslate">
php lib/vendor/symfony/data/bin/check_configuration.php
php lib/vendor/symfony/data/bin/symfony -V
</pre>
<p>If all works fine then there is one other configuration change that is required, after which you can start generating the basic stub of your code base. The change is to update the path <code>sfCoreAutoload.class.php</code> so that its picked up relative to where its placed.</p>
<pre class="brush: bash; title: ; notranslate">
require_once dirname(__FILE__).'/../lib/vendor/symfony/lib/autoload/sfCoreAutoload.class.php';
</pre>
<p>With that done and your basic symfony apps and modules created, you can now update the svn configuration so that you can ignore the <code>cache</code> and <code>logs</code> directory.</p>
<pre class="brush: bash; title: ; notranslate">
$ rm -rf cache/*
$ rm -rf log/*
$ chmod 777 cache
$ chmod 777 log
$ svn add *
$ svn propedit svn:ignore log
$ svn propedit svn:ignore cache
$ svn ci -m &quot;updating the codebase with new apps/modules&quot;
</pre>
<p>Its also a good idea to ensure that the auto generated files dont make it to the repo, which is clearly a waste as its usually good to generate them on the server after deployment, that way you are usually sure about your configurations and settings.</p>
<pre class="brush: bash; title: ; notranslate">
svn add --non-recursive lib/model
svn add --non-recursive lib/model/om
svn add --non-recursive lib/model/map
svn propedit svn:ignore lib/model/om
svn propedit svn:ignore lib/model/map
</pre>
<p>You can also do the same for <code>forms</code> and <code>filters</code> any other auto generated file like sql files). Obviously needless to say, you need to commit your files as often as possible and tag after each release. </p>
<p>This post has been heavily adapted from a post on <a href="http://stereointeractive.com/blog/">Stereo Interactive</a> which is a blog I usually end up on when I get stuck on symfony problems. Worth reading it as well. This post would usually form as my own pointer when starting on the next project on symfony.</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin:0;padding:0;"><div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-bp */
google_ad_slot = "7787511801";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-BP-1 */
google_ad_slot = "9111022353";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2009/02/08/using-svn-for-development-in-symfony/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Looping through values using reference</title>
		<link>http://blog.rajatpandit.com/2009/01/25/looping-through-values-using-reference/</link>
		<comments>http://blog.rajatpandit.com/2009/01/25/looping-through-values-using-reference/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 19:29:17 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[foreach]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=146</guid>
		<description><![CDATA[There are times where you need to loop through a large array and manipulate the items in the array. This is what you usually do. List through items Create a...]]></description>
			<content:encoded><![CDATA[<p>There are times where you need to loop through a large array and manipulate the items in the array. This is what you usually do.</p>
<ul>
<li>List through items</li>
<li>Create a temp array which contains the modified values</li>
<li>Exit the loop and re-assign the new array back to the actual array.</li>
</ul>
<p>This works fine, other than there are some problems with that. </p>
<ul>
<li>You need to create a temp array</li>
<li>Make sure you assign it back to the original array (People make mistakes of not doing that assignment)</li>
</ul>
<p>So here&#8217;s a simpler more easy way to handle this.</p>
<pre class="brush: php; title: ; notranslate">
$items= array('key1' =&gt; 1, 'key2' =&gt; 12, 'key3' =&gt; 3);
foreach($items as $item =&gt; &amp;$value) {
        $value += 20;
        print &quot;$item: $value&quot;;
}
var_dump($items);
</pre>
<p>Note that the <code>$value</code> is assigned a reference, so it doesnt work on a copy of the value but the actual value and hence it retains its value even after exiting the loop. Saw this snippet in <a href="http://symfony-project.org">symfony</a> so thought it was worth mentioning. </p>
<div id="in_post_ad_bottom_1" style="clear:both;margin:0;padding:0;"><div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-bp */
google_ad_slot = "7787511801";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-BP-1 */
google_ad_slot = "9111022353";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2009/01/25/looping-through-values-using-reference/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SimpleXML and parsing namespaced attribute</title>
		<link>http://blog.rajatpandit.com/2009/01/25/simpelxml-and-parsing-namespaced-attribute/</link>
		<comments>http://blog.rajatpandit.com/2009/01/25/simpelxml-and-parsing-namespaced-attribute/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 19:12:01 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[namespaced]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[simplexml]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=147</guid>
		<description><![CDATA[SimpleXML is really good, this is especially more from the heart as its coming from someone who spent a decent amount of time using DOM API to parse xml in...]]></description>
			<content:encoded><![CDATA[<p>SimpleXML is really good, this is especially more from the heart as its coming from someone who spent a decent amount of time using DOM API to parse xml in Java, though XPath was mostly a saviour. I usually get stuck when I there is an edge case or parsing some data format that I haven&#8217;t had to use. Recently I had to parse an XML feed which contained some attributes link this:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;a foo:param=&quot;bla&quot;&gt;Some sample text&lt;/a&gt;
</pre>
<p>Trying to access is using the following code didnt work for me:</p>
<pre class="brush: php; title: ; notranslate">
$attributes = $xml-&gt;a-&gt;attributes('foo');
echo $attributes['param'];
</pre>
<p>However as mentioned in the <a href="http://uk3.php.net/manual/en/function.simplexml-element-attributes.php">manual</a> I needed to explicitly specify that the attribute is prefixed using the second argument. The default value for the second argument is false.</p>
<pre class="brush: php; title: ; notranslate">
$attributes = $xml-&gt;a-&gt;attributes('foo', true);
echo $attributes['param'];
</pre>
<p>I spent a while trying to figure this out, hope this saves you some time. Btw <a href="http://en.wikipedia.org/wiki/SimpleXML">simpleXML</a> is awesome.</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin:0;padding:0;"><div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-bp */
google_ad_slot = "7787511801";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-BP-1 */
google_ad_slot = "9111022353";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2009/01/25/simpelxml-and-parsing-namespaced-attribute/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating clean SEO urls in symfony</title>
		<link>http://blog.rajatpandit.com/2008/06/18/creating-clean-seo-urls-in-symfony/</link>
		<comments>http://blog.rajatpandit.com/2008/06/18/creating-clean-seo-urls-in-symfony/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 12:22:56 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Clean]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[routing]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[YML]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=26</guid>
		<description><![CDATA[Being the symfony fan that I am, I have decided to start documenting some of the features I think are quite neat in the framework. So starting today, here&#8217;s a...]]></description>
			<content:encoded><![CDATA[<p>Being the <a href="http://www.symfony-project.org/">symfony</a> fan that I am, I have decided to start documenting some of the features I think are quite neat in the framework. So starting today, here&#8217;s a quick quite to writing a Search Engine Optimized URL.<br />
So I am working on a project where users will be posting university details and I wanted the university names to appear on the url instead of the id. The problem with ID&#8217;s is it gives too much information about the application and if not carefully design can lead to data being exposed which the development might have not intented do.</p>
<p>So here&#8217;s the url that I was looking for. </p>
<pre class="brush: xml; title: ; notranslate">

http://testsite.rajatpandit.com/university/Indian_institute_of_management_ahemdabad.html
</pre>
<p>I got to the point where I had functional code which gave me URLs like these:</p>
<pre class="brush: xml; title: ; notranslate">

http://testsite.rajatpandit.com/university/id/1
</pre>
<p>These are the steps to convert the URLs are humanly understandable.<br />
Step 1:<br />
Add additional field to the university table to store the modified name. So  update the schema to addt the additional field.<br />
[yml]<br />
university:<br />
    _attribute: {phpName: University}<br />
    id: {type: integer, required: true, primaryKey: true, autoincrement: true}<br />
    name: varchar(256)<br />
    stripped_name: varchar(256)<br />
    website: varchar(256)<br />
    country: varchar(2)<br />
    city: varchar(256)<br />
    body: longvarchar<br />
    approved: boolean<br />
    created_at:<br />
    updated_at:<br />
[/yml]</p>
<p>Obviously  you would need to do the regular to regenerate the models.</p>
<pre class="brush: bash; title: ; notranslate">
#symfony propel-build-model
#symfony propel-build-sql
#symfony propel-insert-sql
</pre>
<p>or do it all in one easy step.</p>
<pre class="brush: bash; title: ; notranslate">
#symfony propel-build-all
</pre>
<p>Step 2:<br />
Now modify the model to update the new column (stripped_name) every time the standard <code>setName($v)</code> is called. For that we need to have a helper function that does this. Here&#8217;s the code I used, you can use your own version.</p>
<pre class="brush: php; title: ; notranslate">
function stripText($text) {
  $text = strtolower($text);
  $text = preg_replace('/\W/', ' ', $text);
  $text = preg_replace('/\ +/', '_', $text);
  $text = preg_replace('/\-$/', '', $text);
  $text = preg_replace('/^\-/', '', $text);
  return $text;
}
</pre>
<p>I create a new file called <code>CustomHelper.php</code> and store in under <code>lib/helper/</code> and then update the model class for <code>University</code> to override the function <code>setName($v)</code> with the following function.</p>
<pre class="brush: php; title: ; notranslate">
public function setName($v)
  {
    include_once('lib/helper/CustomHelper.php');
    parent::setName($v);
    $this-&gt;setStrippedName(stripText($v));
  }
</pre>
<p>That will ensure that the new column <code>stripped_name</code> gets updated.</p>
<p>Step 3:<br />
Update  your php template where you create the links to the following code.</p>
<pre class="brush: php; title: ; notranslate">
&lt;ul&gt;
  &lt;?php foreach($universities as $university): ?&gt;
    &lt;li&gt;
      &lt;?php echo link_to($university-&gt;getName(), '@university_display?stripped_name=' . stripText($university-&gt;getName())); ?&gt;
    &lt;/li&gt;
  &lt;?php endforeach; ?&gt;
&lt;/ul&gt;
</pre>
<p>and update the routing.yml to match the routing name used.</p>
<p>[yml]<br />
article_display:<br />
  url: /article/:stripped_title.html<br />
  param: {module: home, action: article}<br />
[/yml]<br />
The routing rule reads out like this,<br />
When you see the url containing /article/&lt;something&gt;.html redirect it to module: home to its action article and assign a request parameter &lt;stripped_html&gt; to  &lt;something&gt;.</p>
<p>and that&#8217;s all you need to do to get your urls look all nice and clean.</p>
<div id="in_post_ad_bottom_1" style="clear:both;margin:0;padding:0;"><div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-bp */
google_ad_slot = "7787511801";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
<div class="brp-bp-234">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-4254382394977039";
/* brp-234x60-BP-1 */
google_ad_slot = "9111022353";
google_ad_width = 234;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div></div><div style='clear:both'></div>]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2008/06/18/creating-clean-seo-urls-in-symfony/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

