<?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; Web Development</title>
	<atom:link href="http://blog.rajatpandit.com/category/web-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.rajatpandit.com</link>
	<description>Thoughts on Web Development, Scalability and Application Architecture</description>
	<lastBuildDate>Mon, 19 Jul 2010 12:46:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Hand coding a multi-part request and POSTing</title>
		<link>http://blog.rajatpandit.com/2010/07/19/hand-coding-a-multipart-request-and-post-it/</link>
		<comments>http://blog.rajatpandit.com/2010/07/19/hand-coding-a-multipart-request-and-post-it/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 12:45:47 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=547</guid>
		<description><![CDATA[Posting a quick note to myself about how to hand to handcode a multipart request. Required for a REST server/client that I am currently writing. I needed this so that I can post a json object and the associated image in the same post without the typical php name=value paradigm and read from the php://input [...]]]></description>
			<content:encoded><![CDATA[<p>Posting a quick note to myself about how to hand to handcode a multipart request. Required for a REST server/client that I am currently writing. I needed this so that I can post a json object and the associated image in the same post without the typical php name=value paradigm and read from the php://input stream.<br />
However the effort of parsing and un-parsing multipart messages makes me wonder if its just easier to base64 encode the file and send it part of the json object and then un-serialize it at the other end. Shall write more about it later.</p>
<pre class="brush: php;">
$mime_boundary = md5(time());
$data = '--' . $mime_boundary . PHP_EOL;
$data .= 'Content-Disposition: form-data; name=&quot;data&quot;' . PHP_EOL . PHP_EOL;
$data .= &quot;Some Data&quot; . PHP_EOL;
$data .= '--' . $mime_boundary . PHP_EOL;
$data .= 'Content-Disposition: form-data; name=&quot;logo&quot;; filename=&quot;secretfile.jpg&quot;' . PHP_EOL;
$data .= 'Content-Type: image/jpeg' . PHP_EOL;
$data .= 'Content-Transfer-Encoding: base64' . PHP_EOL . PHP_EOL;
$data .= chunk_split(base64_encode($file)) . PHP_EOL;
$data .= &quot;--&quot; . $mime_boundary . &quot;--&quot; . PHP_EOL . PHP_EOL; // finish with two eol's!!
die($data);
$params = array('http' =&gt; array(
                  'method' =&gt; 'POST',
                  'header' =&gt; 'Content-Type: multipart/form-data; boundary=' . $mime_boundary . PHP_EOL,
                  'content' =&gt; $data
               ));

$ctx = stream_context_create($params);
$response = file_get_contents($server, FILE_TEXT, $ctx);
print '--- printing out response ---' . PHP_EOL;
print_r($response);
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2010/07/19/hand-coding-a-multipart-request-and-post-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VirtualBox: Sharing OSX host folder on your ubuntu guest</title>
		<link>http://blog.rajatpandit.com/2010/07/14/virtualbox-sharing-osx-host-folder-on-your-ubuntu-guest/</link>
		<comments>http://blog.rajatpandit.com/2010/07/14/virtualbox-sharing-osx-host-folder-on-your-ubuntu-guest/#comments</comments>
		<pubDate>Wed, 14 Jul 2010 10:20:33 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=542</guid>
		<description><![CDATA[I finally resolved the last bit of annoyance of Virtualbox Related to sharing folders. So here are the steps $ # Create a holder on your host osx $ mkdir -p /websites/topsecretproject/trunk $ # turn off the VM if its on or skip this step $ VBoxManage controlvm 'ubuntu-x11' poweroff $ # Share this folder [...]]]></description>
			<content:encoded><![CDATA[<p>I finally resolved the last bit of annoyance of Virtualbox Related to sharing folders. So here are the steps</p>
<pre class="brush: bash;">
$ # Create a holder on your host osx
$ mkdir -p /websites/topsecretproject/trunk
$ # turn off the VM if its on or skip this step
$ VBoxManage controlvm 'ubuntu-x11' poweroff
$ # Share this folder via VBoxManage, ensure that your VM is turned off
$ VBoxManage sharefolder add &lt;vmname&gt; --name &lt;name&gt; --hostpath &lt;path of the directory on host&gt;
$ # Bootup on the virtual box as headless unless you need to use its gui as well
$ # Ignore this step and boot normally if you want to use the X Server as well on the guest, i dont
$ nohup VBoxHeadless -s 'ubuntu-x11' -v off &amp;
$ # You would want to mount the share as owned by the user on the guest
$ # so you need to get information about the user first
rp@x11-vm:~/code$ id rp
uid=1000(rp) gid=1000(rp) groups=1000(rp),4(adm),20(dialout),24(cdrom),46(plugdev),105(lpadmin),119(admin),122(sambashare)
</pre>
<p>The last step is required to know the group id and user id to mount the share as so that the guest user would have the right set of permissions. Now open up the /etc/fstab and create the following entry. You would obviously need to change the share name and path based on your settings. Mine looks like this.</p>
<pre class="brush: bash;">
# mount the share on the host machine
code            /home/rp/code    vboxsf   defaults,uid=1000,gid=1000 0 0
</pre>
<p>Save the file and exit and then remount all the files with the following command</p>
<pre class="brush: bash;">
rp@x11-vm:~/$ mount -a
rp@x11-vm:~/code$ ls -l
total 4
-rw-r--r-- 1 rp rp 20 2010-07-14 11:05 test.php
</pre>
<p>This will remount all the shares (be careful if you have any other shares currently in use and now when you do an <code>ls</code> in the shared folder you will see all the files are owned by the user in guest and you would the required permissions automatically set. </p>
<p>One of the reasons why I had to go this route was that sshfs didn&#8217;t work very well and macfusion failed to mount (with or without keys) and I couldn&#8217;t get it work. Would be great to hear if any of you have had similar problems and what were the approaches that you took to fix it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2010/07/14/virtualbox-sharing-osx-host-folder-on-your-ubuntu-guest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>nginx configuration for symfony projects</title>
		<link>http://blog.rajatpandit.com/2010/07/06/nginx-configuration-for-symfony-projects/</link>
		<comments>http://blog.rajatpandit.com/2010/07/06/nginx-configuration-for-symfony-projects/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 00:15:43 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=538</guid>
		<description><![CDATA[Documenting my ngnix configuration for new symfony projects, if you got ideas for tweaking this further do leave a comment. server { listen 80; server_name be.aha.sulphur.local; root /websites/aha-be/trunk/web; index index.php; charset utf-8; access_log /var/log/nginx/be.aha.sulphur.access.log; location / { root /websites/aha-be/trunk/web; index index.php; if (-f $request_filename) { expires max; break; } if ($request_filename !~ &#34;\.(js&#124;htc&#124;ico&#124;gif&#124;jpg&#124;png&#124;css)$&#34;) { rewrite [...]]]></description>
			<content:encoded><![CDATA[<p>Documenting my ngnix configuration for new symfony projects, if you got ideas for tweaking this further do leave a comment. </p>
<pre class="brush: bash;">
server {
    listen   80;
    server_name  be.aha.sulphur.local;
    root  /websites/aha-be/trunk/web;
    index index.php;
    charset utf-8;

    access_log  /var/log/nginx/be.aha.sulphur.access.log;

    location / {
          root  /websites/aha-be/trunk/web;
          index  index.php;

          if (-f $request_filename) {
            expires max;
            break;
          }

          if ($request_filename !~ &quot;\.(js|htc|ico|gif|jpg|png|css)$&quot;) {
            rewrite ^(.*) /index.php last;
          }
    }

    location ~ \.php($|/) {
        set  $script     $uri;
        set  $path_info  &quot;&quot;;

        if ($uri ~ &quot;^(.+\.php)(/.+)&quot;) {
                set  $script     $1;
                set  $path_info  $2;
        }

        fastcgi_pass 127.0.0.1:9000;
        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME /websites/aha-be/trunk/web$script;
        fastcgi_param PATH_INFO $path_info;
        fastcgi_param SCRIPT_NAME $script;
        fastcgi_intercept_errors on;
    }

    location /sf/ {
        root /opt/vs/php-5.3.2/lib/php/data/symfony/web/;
        expires max;
    }

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2010/07/06/nginx-configuration-for-symfony-projects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upstart conf file for php-fpm</title>
		<link>http://blog.rajatpandit.com/2010/07/06/upstart-conf-file-for-php-fpm/</link>
		<comments>http://blog.rajatpandit.com/2010/07/06/upstart-conf-file-for-php-fpm/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 23:29:45 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=535</guid>
		<description><![CDATA[Thanks to a messed up vm, I am migrating my dev to a new 10.04 ubuntu vm (which is great since I can now move away from 8.04 JEOS vms). I am taking this opportunity to move to php5.3 and nginx with php running as FCGI where possible. I have in my previous posts talked [...]]]></description>
			<content:encoded><![CDATA[<p>Thanks to a messed up vm, I am migrating my dev to a new 10.04 ubuntu vm (which is great since I can now move away from 8.04 JEOS vms). I am taking this opportunity to move to php5.3 and nginx with php running as FCGI where possible.<br />
I have in my previous posts talked about how to compile and patch php to get the php-fpm interface, however manually starting it with every-reboot can be a pain, so here&#8217;s the upstart script for it.</p>
<p>Create a new file /etc/init/php-fpm and past the following contents inside it:</p>
<pre class="brush: bash;">
description &quot;PHP FastCGI Process Manager&quot;
start on {net-device-up and local-filesystems}
stop on runlevel [016]

expect fork
respawn
exec /usr/sbin/php-fpm --fpm-config /etc/php/php-fpm.conf
</pre>
<p>Obviously tweak the path and configuration to your hearts content. Hope this will help someone who is lazy like me and doesn&#8217;t like writing the same commands over and over again.</p>
<p>Also to start the service then, run the following command:</p>
<pre class="brush: bash;">
$ sudo initctl start php-fpm
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2010/07/06/upstart-conf-file-for-php-fpm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VirtualBox port forwarding, running headless and disabling GDM on 10.04</title>
		<link>http://blog.rajatpandit.com/2010/07/02/virtualbox-port-forwarding-running-headless-and-disabling-gdm-on-10-04/</link>
		<comments>http://blog.rajatpandit.com/2010/07/02/virtualbox-port-forwarding-running-headless-and-disabling-gdm-on-10-04/#comments</comments>
		<pubDate>Fri, 02 Jul 2010 10:22:56 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=532</guid>
		<description><![CDATA[Phew that was a long heading. Things have changed in VirtualBox 3.2.4, setting up port forwarding is lot easier now and more readable. Adding notes for setting up and configuring my linux dev vm. Install or import a new appliance and disable gdm, if all you need to do is run a couple of services [...]]]></description>
			<content:encoded><![CDATA[<p>Phew that was a long heading. Things have changed in VirtualBox 3.2.4, setting up port forwarding is lot easier now and more readable. Adding notes for setting up and configuring my linux dev vm.</p>
<p>Install or import a new appliance and disable gdm, if all you need to do is run a couple of services on it, no point wasting memory running gdm.<br />
Edit grub configuration</p>
<pre class="brush: bash;">
sudo vi /etc/default/grub
</pre>
<p> and edit the following lines.</p>
<pre class="brush: bash;">
#GRUB_CMDLINE_LINUX_DEFAULT=&quot;quiet splash&quot;
GRUB_CMDLINE_LINUX_DEFAULT=&quot;text&quot;
</pre>
<p>comment out the first line and add the second one and then update the conf</p>
<pre class="brush: bash;">
sudo update-grub2
</pre>
<p>Now setup/install ssh atleast before you configure anything else.</p>
<pre class="brush: bash;">
sudo apt-get install openssh-server
</pre>
<p>Now reboot the vm to test if it all boots fine and doesn&#8217;t start the X server. Now turn it off again and this time boot it again as headless so its just a process like any other program running on your computer and possibly more efficient in terms of memory requirement.</p>
<p>But before that configure port forwarding. The syntax is for network connection setup as NAT</p>
<pre class="brush: bash;">
VBoxManage     modifyvm     [--natpf&lt;1-N&gt; [&lt;rulename&gt;],tcp|udp,[&lt;hostip&gt;],
                                          &lt;hostport&gt;,[&lt;guestip&gt;],&lt;guestport&gt;]
                                              [--natpf&lt;1-N&gt; delete &lt;rulename&gt;]
</pre>
<p>So based on this, to setup port forwarding from localhost port 2222 to guest port 22, the following and start the vm headless.</p>
<pre class="brush: bash;">
mac-host:~rpandit1016$ VBoxManage modifyvm &quot;ubuntu-x11&quot; --natpf1 &quot;guestssh, tcp,, 2222,, 22&quot;
mac-host:~ rpandit1016$ VBoxHeadless --startvm &quot;ubuntu-x11&quot;
Oracle VM VirtualBox Headless Interface 3.2.4
(C) 2008-2010 Oracle Corporation
All rights reserved.

Listening on port 3389.
</pre>
<p>Now you can configure more services by logging in. Remember to ensure that your VM is switched off though when you want to add a new rule, otherwise it will fail everytime you try and add it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2010/07/02/virtualbox-port-forwarding-running-headless-and-disabling-gdm-on-10-04/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Post a file using CURL/PHP</title>
		<link>http://blog.rajatpandit.com/2010/06/27/post-a-file-using-curlphp/</link>
		<comments>http://blog.rajatpandit.com/2010/06/27/post-a-file-using-curlphp/#comments</comments>
		<pubDate>Sun, 27 Jun 2010 15:20:57 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=529</guid>
		<description><![CDATA[Streams are pretty much the forgotten features in php, I don&#8217;t see many people making use of it, partially because it works transparently under the hood when we use php&#8217;s functions to read/write from the disk or network. I shall write about how you can create custom stream handlers and protocols in php in userland [...]]]></description>
			<content:encoded><![CDATA[<p>Streams are pretty much the forgotten features in php, I don&#8217;t see many people making use of it, partially because it works transparently under the hood when we use php&#8217;s functions to read/write from the disk or network. I shall write about how you can create custom stream handlers and protocols in php in userland which is pretty amazing, however for now I am documenting one of the crazy things I noticed in php.</p>
<p>I am currently writing a plugin for a web-service which allows you to post files to it. Its pretty simple, your code would use the plugin and then pass the uploaded file as an argument and it will post it to the endpoint of the web-service. You can read raw POST data using the <code>php://input</code> format which will give you the contents of a post looking similar to a query string, however if you wanted to upload a file, you can&#8217;t use the same to read the file directly to the stream. Part of what I was trying to accomplish with streams was to be able to write the file to an S3 server, however sadly there is no way (or atleast not that I know of to intercept the file before it gets written to the disk to avoid the wasted IO overhead).</p>
<p>Interestingly you can always post using the <code>libCurl</code> functions in php, however there is a little gottcha that I didn&#8217;t know about and that&#8217;s documented as the  RFC1867-posting implementation of curl. So to upload a file using the command line curl in the same way as you would do with a multipart form you can run the following command along with the response, which is basically a dump of the <code>$_POST</code> and <code>$_FILES</code> global variables.</p>
<pre class="brush: bash;">
leonardo:foo rp$ curl -F upload=@nav_logo13.png -f  http://scratch.local/foo/server.php
Array
(
)
Array
(
    [upload] =&gt; Array
        (
            [name] =&gt; nav_logo13.png
            [type] =&gt; application/octet-stream
            [tmp_name] =&gt; /tmp/phpNLOAew
            [error] =&gt; 0
            [size] =&gt; 28736
        )

)
</pre>
<p><strong>Note:</strong> Notice the @ sign before the file name, this is where the gottcha exists. Translating this into php code.</p>
<pre class="brush: php;">
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// true to return the transfer as a string of the return value
// of 'curl_exec' instead of outputting it directly
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

curl_setopt($ch, CURLOPT_USERAGENT, &quot;Mozilla/4.0 (compatible;)&quot;);
curl_setopt($ch, CURLOPT_URL, 'http://scratch.local/foo/server.php');
curl_setopt($ch, CURLOPT_POST, true);
$post = array(
  'logo' =&gt; '@nav_logo13.png',
  'first_name' =&gt; 'Rajat'
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
print_r($response);
</pre>
<p>Cleanup the code to use the bits that apply in your context but this is pretty much that it involves. Pretty interesting though I wish there was a better way, one of the ways would be to possibly run my own server  using <code>stream_accept_socket</code> and then read directly from the socket but there is all this additional layer that I can get out of HTTP that I don&#8217;t want to loose. </p>
<p>Does anyone have a better idea? suggestions welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2010/06/27/post-a-file-using-curlphp/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>php 5.3.x / php-fpm / nginx</title>
		<link>http://blog.rajatpandit.com/2010/06/23/php-5-3-x-php-fpm-nginx/</link>
		<comments>http://blog.rajatpandit.com/2010/06/23/php-5-3-x-php-fpm-nginx/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 19:50:34 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=523</guid>
		<description><![CDATA[I have started moving my dev environments from apache to ngnix for various reasons, mostly because ngnix has a smaller footprint and lets me get more out of low memory vms. I would probably write another post later about the reasons for switching from apache to ngnix for now, here are my notes for getting [...]]]></description>
			<content:encoded><![CDATA[<p>I have started moving my dev environments from apache to ngnix for various reasons, mostly because ngnix has a smaller footprint and lets me get more out of low memory vms. I would probably write another post later about the reasons for switching from apache to ngnix for now, here are my notes for getting the php5.3.x/php-fpm and nginix working together. I should probably automate this process using hudson/puppet/chef configuration but that&#8217;s again an exercise for later. </p>
<p>Notes:<br />
Install the required basic development tools (especially if you are using a new vm/install)</p>
<pre class="brush: bash;">
$ sudo apt-get install make bison flex gcc patch autoconf subversion locate
$ sudo apt-get install libxml2-dev libbz2-dev libpcre3-dev libssl-dev zlib1g-dev libmcrypt-dev libmhash-dev libmhash2 libcurl4-openssl-dev libpq-dev --with-mysql --with-pdo-mysql
</pre>
<p>Download and patch php 5.3</p>
<pre class="brush: bash;">
$ cd /usr/local/src
$ sudo wget http://uk.php.net/get/php-5.3.2.tar.gz/from/this/mirror
$ sudo tar zxvf  php-5.3.2.tar
$ cd /usr/local/src/php-5.3.2
$ sudo svn co http://svn.php.net/repository/php/php-src/branches/PHP_5_3/sapi/fpm sapi/fpm
$ sudo ./buildconf --force
$ sudo ./configure --enable-fpm --with-mcrypt --with-zlib --enable-mbstring --enable-pdo --with-curl --enable-inline-optimization --with-bz2  --with-zlib --enable-sockets --enable-mbregex --with-mhash --enable-xslt  --enable-zip --with-pcre-regex --with-mysql --with-pdo-mysql
</pre>
<p>Now do the regular <code>configure</code>, <code>make</code>, <code>make test</code> and <code>make install </code></p>
<p>If you are a purist and want to remove all the symbols in php, run the following command, personally I leave it as it is:</p>
<pre class="brush: bash;">
$sudo strip /usr/local/bin/php-cgi
</pre>
<p>Also if you want the mecache and apc goodness then run the following commands</p>
<pre class="brush: bash;">
$ sudo pecl install memcache
$ sudo pecl install apc
</pre>
<p>Now prepare for the configuration values:</p>
<pre class="brush: bash;">
$ sudo cp /usr/local/src/php-5.3.2/php.ini-development /usr/local/lib/php.ini #if you for dev, else choose recc
$ sudo mkdir /etc/php
$ sudo ln -s /usr/local/lib/php.ini /etc/php/php.ini
$ sudo ln -s /usr/local/etc/php-fpm.conf /etc/php/php-fpm.conf
</pre>
<p>The other important that needs doing is changing the user permissions in the php-fpm.conf file. It should basically be the same user with which ngnix user runs. It was <code>www-data</code> in my case.</p>
<p>Next step is to install Ngnix. There are tons of tutorials on the internet so not going to cover it. If you are on a debian based system, you can install it quickly using the apt-get command.</p>
<pre class="brush: bash;">
$ sudo apt-get install nginx
</pre>
<p>Now its time to start the php-fpm process, which you can do by running this as root.</p>
<pre class="brush: bash;">
$ sudo php-fpm -y /etc/php/php-fpm.conf
</pre>
<p>There might be a few more tweaks that need doing in the php-fpm.conf but leave that an exercise for the reader.</p>
<p>Now, tweak the ngnix host files under the <code>/etc/nginx/sites-available </code> to your hearts content and enable the <code>fastcgi</code> module in it. I shall cover its configuration in detail in the next posts. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2010/06/23/php-5-3-x-php-fpm-nginx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parsing massive XML documents using XMLReader</title>
		<link>http://blog.rajatpandit.com/2010/06/23/parsing-massive-xml-documents-using-xmlreader/</link>
		<comments>http://blog.rajatpandit.com/2010/06/23/parsing-massive-xml-documents-using-xmlreader/#comments</comments>
		<pubDate>Wed, 23 Jun 2010 19:26:10 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[DOM]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[SAX]]></category>
		<category><![CDATA[xml]]></category>
		<category><![CDATA[XMLReader]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=525</guid>
		<description><![CDATA[I recently had the need to parse a massive (2gb) xml file and read it back to the database, the standard approach of SimpleXML and Dom was not going to work. I wanted to use XMLReader for this purpose. So here are the quick notes for helping anyone getting upto speed of what the quick [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had the need to parse a massive (2gb) xml file and read it back to the database, the standard approach of <code>SimpleXML</code> and <code>Dom</code> was not going to work. I wanted to use <a href="http://uk.php.net/XMLReader">XMLReader</a> for this purpose. So here are the quick notes for helping anyone getting upto speed of what the quick start code looks like.</p>
<p>Quoting from its website:</p>
<blockquote><p>
The XMLReader extension is an XML Pull parser. The reader acts as a cursor going forward on the document stream and stopping at each node on the way.</p></blockquote>
<pre class="brush: php;">
// create the reader object
$reader = new XMLReader();

// reader the XML file.
$reader-&gt;open($abms_file);

// start reading the XML File.
while($reader-&gt;read()) {
    // take action based on the kind of node returned
   switch($reader-&gt;nodeType) {
       // read more http://uk.php.net/manual/en/class.xmlreader.php#xmlreader.constants.element
       case (XMLREADER::ELEMENT):
              // get the name of the node.
              $node_name  = $reader-&gt;name;
              // move the pointer to read the next item
              $reader-&gt;read();
              // action based on the $node_name
           break;
       case (XMLREADER::END_ELEMENT):
            // do something based on when the element closes.
            break;
   }
}
</pre>
<p>Pretty handy is this parsing method since it scales well for huge documents as well as for tiny documents and the memory footprint remains consistently the same.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2010/06/23/parsing-massive-xml-documents-using-xmlreader/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Fixing backspace in screen in terminal on OSX</title>
		<link>http://blog.rajatpandit.com/2010/06/17/fixing-backspace-in-screen-in-terminal-on-osx/</link>
		<comments>http://blog.rajatpandit.com/2010/06/17/fixing-backspace-in-screen-in-terminal-on-osx/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 20:02:20 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[snow leopard]]></category>
		<category><![CDATA[ssh]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=519</guid>
		<description><![CDATA[Screen is awesome, I am surprised I never bothered to learn about it earlier. It all stemmed from the fact that I was working on a pretty low powered VM and couldn&#8217;t afford to open multiple xterms on it. Later when I started SSH&#8217;ing into it the screen utility came in pretty handy, however when [...]]]></description>
			<content:encoded><![CDATA[<p>Screen is awesome, I am surprised I never bothered to learn about it earlier. It all stemmed from the fact that I was working on a pretty low powered VM and couldn&#8217;t afford to open multiple xterms on it. Later when I started SSH&#8217;ing into it the screen utility came in pretty handy, however when you are on OSX and ssh into a remote box and use screen, when you hit backspace, it doesn&#8217;t instead gets the screen to give you a &#8216;wuff &#8212; wuff&#8217; and I am not kidding, that&#8217;s the default message.<br />
The fix is simple, run this on the console, close and restart, sorted.</p>
<pre class="brush: bash;">
defaults write com.apple.Terminal TermCapString xterm
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2010/06/17/fixing-backspace-in-screen-in-terminal-on-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>phing phplint out of memory</title>
		<link>http://blog.rajatpandit.com/2010/05/26/phing-phplint-out-of-memory/</link>
		<comments>http://blog.rajatpandit.com/2010/05/26/phing-phplint-out-of-memory/#comments</comments>
		<pubDate>Wed, 26 May 2010 14:12:13 +0000</pubDate>
		<dc:creator>rp</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[memory_limit]]></category>
		<category><![CDATA[Phing]]></category>
		<category><![CDATA[phplint]]></category>

		<guid isPermaLink="false">http://blog.rajatpandit.com/?p=516</guid>
		<description><![CDATA[Had a funny problem at work today, my php.ini was set to 1G however the script would still fail saying it couldn&#8217;t allocate 32bytes of memory which was a bit odd. A little investigation showed that at lib/php/phing/Phing.php // should return memory limit in MB $mem_limit = (int) ini_get('memory_limit'); if ($mem_limit &#60; 32) { // [...]]]></description>
			<content:encoded><![CDATA[<p>Had a funny problem at work today, my php.ini was set to 1G however the script would still fail saying it couldn&#8217;t allocate 32bytes of memory which was a bit odd. A little investigation showed that at <code>lib/php/phing/Phing.php</code></p>
<pre class="brush: php;">

        // should return memory limit in MB
        $mem_limit = (int) ini_get('memory_limit');
        if ($mem_limit &lt; 32) {
            // We do *not* need to save the original value here, since we don't plan to restore
            // this after shutdown (we don't trust the effectiveness of PHP's garbage collection).
            ini_set('memory_limit', '32M'); // nore: this may need to be higher for many projects
        }
</pre>
<p>contained this interesting bit of code, so <code> (int) ini_get('memory_limit') </code> return 1 instead of something more sensible. Pretty failsome way to detect how much memory is allocated, assuming the entire world would be setting the memory in megabytes. Why is our php.ini set to 1G is another story.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.rajatpandit.com/2010/05/26/phing-phplint-out-of-memory/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
