<?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>Zeta-Puppis.com &#187; PHP</title>
	<atom:link href="http://zeta-puppis.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://zeta-puppis.com</link>
	<description>my very own personal corner</description>
	<lastBuildDate>Wed, 07 Apr 2010 15:36:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>When the &#8220;Python Vs PHP&#8221; war matters</title>
		<link>http://zeta-puppis.com/2008/02/21/when-the-python-vs-php-war-matters/</link>
		<comments>http://zeta-puppis.com/2008/02/21/when-the-python-vs-php-war-matters/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 19:45:52 +0000</pubDate>
		<dc:creator>kratorius</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[IT]]></category>
		<category><![CDATA[mvc]]></category>
		<category><![CDATA[symfony]]></category>

		<guid isPermaLink="false">http://zeta-puppis.com/2008/02/21/when-the-python-vs-php-war-matters/</guid>
		<description><![CDATA[Yesterday I had a meeting with a customer about a new site I should develop for them. Since they&#8217;re a book publisher, they wanted an online book store. Apart from the technical details (the site isn&#8217;t as simple as you may believe, they need a lot of not-so-easy-to-do stuff), the most important point we focused [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I had a meeting with a customer about a new site I should develop for them. Since they&#8217;re a book publisher, they wanted an online book store. Apart from the technical details (the site isn&#8217;t as simple as you may believe, they need a lot of not-so-easy-to-do stuff), the most important point we focused on is the fact that <strong>they have an internal IT technician</strong> that handles all their computer needs. If you&#8217;re asking yourself why this matters, keep&nbsp;reading:</p>
<ul>
<li>me (to be precise, my company) stopped development of PHP sites about one year ago in favor of&nbsp;Python</li>
<li>we release the web site&#8217;s code to&nbsp;them</li>
<li>for this project, <strong>we haven&#8217;t been asked any kind of future support</strong>; this means that when the site is finished, we won&#8217;t touch the product anymore (unless they don&#8217;t pay us to do the modifies they&nbsp;need)</li>
<li>but they don&#8217;t want to pay us to these modifies, because they have their internal IT&nbsp;technician</li>
<li><strong>their technician knows only PHP</strong> (and he never even known the Python&#8217;s existence until&nbsp;yesterday)</li>
</ul>
<p><span id="more-82"></span></p>
<p>So I had to illustrate why me and my company chosen Python for our web development needs, and here&#8217;s a summary of what I told them yesterday. Note that <strong>I&#8217;m not talking about why a language is better than the other</strong>, because this would move us in another direction, but <strong>why we chosen Python as our main programming language</strong> (even if this unconsciously lead us to say why, for us, Python is better than PHP, but that&#8217;s another story)&nbsp;:</p>
<ul>
<li><strong>Time</strong>: remember that time is money. If I&#8217;d build an application in PHP, I&#8217;d spend about 1/3 of the time more if I&#8217;d develop the same application in&nbsp;Python</li>
<li><strong>Frameworks</strong>: nowadays all the popular languages have their web frameworks; Ruby has <a href="http://www.rubyonrails.org/">Ruby on Rails</a>, PHP has <a href="http://www.symfony-project.org/">Symfony</a>, <a href="http://www.phpmvc.net/">php.MVC</a>, Python has <a href="http://djangoproject.com/">Django</a>, <a href="http://www.cherrypy.org/">CherryPy</a>, <a href="http://pylonshq.com/">Pylons</a>, and so on. But none of them (apart from rails, but we&#8217;re talking about PHP Vs Python) goes near to the completeness and functionality of django. And this take us at the previous point: less time in develop the same&nbsp;application</li>
<li><strong>Future modifies</strong>: even if for this project this isn&#8217;t the case, it&#8217;s much easier to modify a Python application than a PHP one due to the syntax of the language and its strong <a href="http://en.wikipedia.org/wiki/Object-oriented_programming">OOP</a> orientation. You may argue that PHP 5 introduced a deep OOP support too, but that&#8217;s not the same thing and you know. PHP is born as procedural programming language, and even if we had OOP introduction in version 5, it doesn&#8217;t even comes near to Python under this point of&nbsp;view</li>
</ul>
<p>With this I&#8217;m not saying that PHP is useless: what I mean is that <strong>Python is more convenient under the (our) business point of view</strong>. So if someone ask me why I use Python to do the same thing I can make with PHP, the answer will be: because with Python I can make the same thing in a shorter time and, consequently, with a lower&nbsp;budget.</p>
]]></content:encoded>
			<wfw:commentRss>http://zeta-puppis.com/2008/02/21/when-the-python-vs-php-war-matters/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>PHP, PATH_INFO and url-friendly site</title>
		<link>http://zeta-puppis.com/2006/04/09/php-path_info-and-url-friendly-site/</link>
		<comments>http://zeta-puppis.com/2006/04/09/php-path_info-and-url-friendly-site/#comments</comments>
		<pubDate>Sun, 09 Apr 2006 14:52:00 +0000</pubDate>
		<dc:creator>kratorius</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://kratorius.simosnap.net/2006/04/09/php-path_info-and-url-friendly-site/</guid>
		<description><![CDATA[These days I had to redesign a company&#8217;s site layout, due to hosting services upgrades. Before, they were simple static HTML pages: now, they are (not really, they are about to be&#8230;) dynamic generated ones. I cannot use mod_rewrite since the hoster disabled it due to security issues (?).
So I had to look for other [...]]]></description>
			<content:encoded><![CDATA[<p>These days I had to redesign a company&#8217;s site layout, due to hosting services upgrades. Before, they were simple static HTML pages: now, they are (not really, they are about to be&#8230;) dynamic generated ones. I cannot use <code>mod_rewrite</code> since the hoster disabled it due to security issues (?).<br />
So I had to look for other ways to get a URL-friendly site. The answer came from the <code>phpinfo();</code> function. I looked at the generated page if there were some parameter that well fits to have a URL friendly site. So I discovered <code>PATH_INFO</code>.<br />
I&#8217;m using PHP since a long time but I never heard such a feature, so I had to learn something new.<br />
We can have, in this way, a URL like this: <em>http://www.site.com/page.php/section/subsection/subsubsection</em> that can easily become using apache <code>.htaccess</code> (if the hoster supports it, obviously) like this: <em>http://www.site.com/page/section/subsection/subsubsection</em>, hence by removing the <code>.php</code> extension and by make the php page as another subdirectory (I&#8217;ll describe how to do this&nbsp;later).</p>
<p>So let start looking at how <code>PATH_INFO</code> works.<br />
First of all, let create a page called <code>page.php</code> that will handle the parameter passing. Now let suppose that we are passing a URL like this: <code>/page.php/section/subsection</code>. We will found in <code>PATH_INFO</code> something like this: <code>/section/subsection</code>. Hence, suppose we want to show the file named &#8220;section_subsection.php&#8221; in the <code>pages/</code> directory. Simply, a <code>$array = explode('/', $_SERVER['PATH_INFO']);</code> will give us &#8220;section&#8221; into <code>$array[0]</code> and &#8220;subsection&#8221; into <code>$array[1]</code>. Now you just need to concatenate the two array elements and adding <code>.php</code> (or whatever you want) extension and, after checking the file existance, you&#8217;ll have the work&nbsp;done.</p>
<p>Thats the code I used in order to achieve such effect (the code that&#8217;s in production, I am still working on it so it may have some&nbsp;error):</p>
<pre><code>&amp;lt;?php
  require(dirname(__FILE__) . "/config.php");
  require(dirname(__FILE__) . "/functions.php");

  $exclude_list = array("img", "frontpage");

  if (!isset($_SERVER['PATH_INFO']))
    header("Location: {$_CONFIG['url']}{$_CONFIG['pager']}/home");
  else $tpath = $_SERVER['PATH_INFO'];

  $tpath = explode('/', $tpath);
  $path = $tpath[1];
  if (isset($tpath[2]))
    $subpath = $tpath[2];
  else $subpath = "";

  $exclude = FALSE;
  foreach($exclude_list as $exc)
    if ($exc == $path)
      $exclude = TRUE;

  if (!$exclude) {
    if ((count($tpath) &amp;gt; 3) || (!file_exists(dirname(__FILE__) . "/pages/" . $path . ".php")))
      $page = "/pages/404.php";
    else {
      // if $subpath exists, we have /path/subpath, traslated as path_subpath.php
      if ($subpath !== "")
        $page = "/pages/" . $path . "_" . $subpath . ".php";
      else $page = "/pages/$path.php";
    }

    ob_start("ob_gzhandler");
    require(dirname(__FILE__) . "/head.php");
    require(dirname(__FILE__) . "/title.php");
    require(dirname(__FILE__) . "/menu.php");
    echo "&amp;lt;div id="content"&amp;gt;n";
    require(dirname(__FILE__) . $page);
    echo "&amp;lt;/div&amp;gt; &amp;lt;!--/content --&amp;gt;n";
    require(dirname(__FILE__) . "/footer.php");
    ob_end_flush();
  } else {
    $fullpath = implode('/', $tpath);
    $fp = fopen(dirname(__FILE__) . $fullpath, "r");
    $contents = fread($fp, filesize(dirname(__FILE__) . $fullpath));
    echo $contents;
  }
?&amp;gt;</code></pre>
<p>Let analize it. Firstly, why do we have an <code>$exclude_list</code>? This is needed because with this way of URL handling, <strong>every file</strong> that we will request under the site path will pass from that script. So, since we want to display images and other things, just take the file as they are and print them out if such path is in the exclude list.<br />
I used a couple of <code>$_CONFIG</code> values (that I define in config.php) to have a centralized configuration system. Specifically, <code>$_CONFIG['url']</code> will contain the site&#8217;s URL, while <code>$_CONFIG['pager']</code> will contain the filename of the script that will handle the <code>PATH_INFO</code> data, in our case&nbsp;page.php.</p>
<p>Successively, there&#8217;s a check about the file existence into the <code>/pages</code> directory. The rest is just the use of the buffered output since I sometimes use a <code>header()</code> call in the other pages both to redirect the user to some other page and to set the right errorcode for a 404&nbsp;page.</p>
<p>Of course there are some improvements that could be done. Probably, the most important limitation in the script now is that it has a limit of two subsections (like /section/subsection). This limit could be expanded by doing something like this: <code>implode('_', explode('/', $tpath));</code> but will need more checks for&nbsp;consistency.</p>
<p>Another thing: as I said before, you could want to delete the .php suffix on the page.php. This can be done by putting this lines in the&nbsp;.htaccess:</p>
<pre><code>&amp;lt;files page&amp;gt;
ForceType application/x-httpd-php
&amp;lt;/files&amp;gt;</code></pre>
<p>In this way we will force apache to call <code>page.php</code> if it is called as <code>page</code>&nbsp;only.</p>
<p>That&#8217;s all :) I have to make shorter posts, I&nbsp;know.</p>
]]></content:encoded>
			<wfw:commentRss>http://zeta-puppis.com/2006/04/09/php-path_info-and-url-friendly-site/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
