<?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>Made of Everything You&#039;re Not &#187; apache</title>
	<atom:link href="http://blog.ericlamb.net/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ericlamb.net</link>
	<description>Thoughts on programming, people and life</description>
	<lastBuildDate>Wed, 11 Aug 2010 03:58:55 +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>Parse Apache Log Files With PHP</title>
		<link>http://blog.ericlamb.net/2010/01/parse-apache-log-files-with-php/</link>
		<comments>http://blog.ericlamb.net/2010/01/parse-apache-log-files-with-php/#comments</comments>
		<pubDate>Sat, 09 Jan 2010 08:35:41 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=2837</guid>
		<description><![CDATA[Parsing the log files generated by Apache is one of those random tasks with a random occurrence in my world. This is a task that, until recently, hadn&#8217;t come up enough to warrant any sort of a ready solution (and it was just fun enough to be ok to write a custom solution). So every [...]]]></description>
			<content:encoded><![CDATA[<p>Parsing the log files generated by Apache is one of those random tasks with a random occurrence in my world. This is a task that, until recently, hadn&#8217;t come up enough to warrant any sort of a ready solution (and it was just fun enough to be <em>ok </em>to write a custom solution). So every time this came up I would always fire up Google and go on a scavenger hunt for a starter script written in php.</p>
<div id="attachment_2841" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.ericlamb.net/wp-content/uploads/2010/01/apache.jpg" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2010%2F01%2Fapache.jpg','Parse+Apache+Log+Files+With+PHP')"><img src="http://blog.ericlamb.net/wp-content/uploads/2010/01/apache-300x225.jpg" alt="Parse Apache Log Files With PHP" title="Parse Apache Log Files With PHP" width="300" height="225" class="size-medium wp-image-2841" /></a><p class="wp-caption-text">Parse Apache Log Files With PHP</p></div>
<p>This always felt like a good idea at the time the need came up. These days, for some ungodly reason, parsing Apache logs seems to come up a little too frequently to keep this up. In the spirit of making my life a hell of a lot easier for tomorrow I&#8217;ve taken a shot at writing an Apache log parser written in PHP.</p>
<p>One thing I decided to implement is a filtering system so you can filter out based on a provided regex. Might not be too useful to everyone but it should be trivial to remove the functionality.</p>
<p>Anyway, I hope someone finds this useful (even to learn from and, of course, use)</p>
<p>Here&#8217;s the main class:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #009933; font-style: italic;">/**
 * Apache Log Parser
 * Parses an Apache log file and runs the strings through filters to find what you're looking for.
 * @author Eric Lamb
 *
 */</span>
<span style="color: #000000; font-weight: bold;">class</span> apache_log_parser
<span style="color: #000;">&#123;</span>
	<span style="color: #009933; font-style: italic;">/**
	 * The path to the log file
	 * @var string
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$file</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * What filters to apply. Should be in the format of array('KEY_TO_SEARCH' =&gt; array('regex' =&gt; 'YOUR_REGEX'))
	 * @var array
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000088;">$filters</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Duh.
	 * @param string $file
	 * @return void
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #000;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #000;">&#41;</span>
	<span style="color: #000;">&#123;</span>
		<span style="color: #22f;">if</span><span style="color: #000;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_readable</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$file</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span>
		<span style="color: #000;">&#123;</span>
			<span style="color: #22f;">return</span> 	<span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
		<span style="color: #000;">&#125;</span>
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">file</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$file</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Executes the supplied filter to the string
	 * @param $filer
	 * @param $status
	 * @return string
	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> applyFilters<span style="color: #000;">&#40;</span><span style="color: #000088;">$str</span><span style="color: #000;">&#41;</span>
	<span style="color: #000;">&#123;</span>
		<span style="color: #22f;">if</span><span style="color: #000;">&#40;</span><span style="color: #339933;">!</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">filters</span> <span style="color: #339933;">||</span> <span style="color: #339933;">!</span><span style="color: #990000;">is_array</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">filters</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span>
		<span style="color: #000;">&#123;</span>
			<span style="color: #22f;">return</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
		<span style="color: #000;">&#125;</span>
&nbsp;
		<span style="color: #22f;">foreach</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">filters</span> <span style="color: #22f;">AS</span> <span style="color: #000088;">$area</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$filter</span><span style="color: #000;">&#41;</span>
		<span style="color: #000;">&#123;</span>
			<span style="color: #22f;">if</span><span style="color: #000;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$filter</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'regex'</span><span style="color: #000;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$str</span><span style="color: #000;">&#91;</span><span style="color: #000088;">$area</span><span style="color: #000;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #339933;">,</span> PREG_OFFSET_CAPTURE<span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span>
			<span style="color: #000;">&#123;</span>
				<span style="color: #22f;">return</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
			<span style="color: #000;">&#125;</span>
		<span style="color: #000;">&#125;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Returns an array of all the filtered lines 
	 * @param $limit
	 * @return array
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getData<span style="color: #000;">&#40;</span><span style="color: #000088;">$limit</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #000;">&#41;</span>
	<span style="color: #000;">&#123;</span>
		<span style="color: #000088;">$handle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">file</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rb'</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #22f;">if</span> <span style="color: #000;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
			<span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$lines</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		    <span style="color: #22f;">while</span> <span style="color: #000;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">feof</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span> <span style="color: #000;">&#123;</span>
		        <span style="color: #000088;">$buffer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fgets</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		        <span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">applyFilters</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">format_line</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$buffer</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		        <span style="color: #22f;">if</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #000;">&#41;</span>
		        <span style="color: #000;">&#123;</span>
		        	<span style="color: #000088;">$lines</span><span style="color: #000;">&#91;</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #339933;">;</span>
		        <span style="color: #000;">&#125;</span>
&nbsp;
		        <span style="color: #22f;">if</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$limit</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$count</span> <span style="color: #339933;">==</span> <span style="color: #000088;">$limit</span><span style="color: #000;">&#41;</span>
		        <span style="color: #000;">&#123;</span>
		        	<span style="color: #22f;">break</span><span style="color: #339933;">;</span>
		        <span style="color: #000;">&#125;</span>
		        <span style="color: #000088;">$count</span><span style="color: #339933;">++;</span>
		    <span style="color: #000;">&#125;</span>
		    <span style="color: #990000;">fclose</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$handle</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
		    <span style="color: #22f;">return</span> <span style="color: #000088;">$lines</span><span style="color: #339933;">;</span>
		<span style="color: #000;">&#125;</span>		
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Regex to parse the log file line
	 * @param string $line
	 * @return array
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> format_log_line<span style="color: #000;">&#40;</span><span style="color: #000088;">$line</span><span style="color: #000;">&#41;</span>
	<span style="color: #000;">&#123;</span>
		<span style="color: #990000;">preg_match</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">&quot;/^(\S+) (\S+) (\S+) \[([^:]+):(\d+:\d+:\d+) ([^\]]+)\] <span style="color: #000099; font-weight: bold;">\&quot;</span>(\S+) (.*?) (\S+)<span style="color: #000099; font-weight: bold;">\&quot;</span> (\S+) (\S+) (<span style="color: #000099; font-weight: bold;">\&quot;</span>.*?<span style="color: #000099; font-weight: bold;">\&quot;</span>) (<span style="color: #000099; font-weight: bold;">\&quot;</span>.*?<span style="color: #000099; font-weight: bold;">\&quot;</span>)$/&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$line</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// pattern to format the line</span>
		<span style="color: #22f;">return</span> <span style="color: #000088;">$matches</span><span style="color: #339933;">;</span>
	<span style="color: #000;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**
	 * Takes the format_log_line array and makes it usable to us stupid humans
	 * @param $line
	 * @return array
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> format_line<span style="color: #000;">&#40;</span><span style="color: #000088;">$line</span><span style="color: #000;">&#41;</span>
	<span style="color: #000;">&#123;</span>
		<span style="color: #000088;">$logs</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">format_log_line</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$line</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// format the line</span>
&nbsp;
		<span style="color: #22f;">if</span> <span style="color: #000;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #000;">&#40;</span><span style="color: #000088;">$logs</span><span style="color: #000;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #000;">&#93;</span><span style="color: #000;">&#41;</span><span style="color: #000;">&#41;</span> <span style="color: #666666; font-style: italic;">// check that it formated OK</span>
		<span style="color: #000;">&#123;</span>
			<span style="color: #000088;">$formated_log</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// make an array to store the lin info in</span>
			<span style="color: #000088;">$formated_log</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'ip'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$logs</span><span style="color: #000;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$formated_log</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'identity'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$logs</span><span style="color: #000;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$formated_log</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'user'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$logs</span><span style="color: #000;">&#91;</span><span style="color: #cc66cc;">2</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$formated_log</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'date'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$logs</span><span style="color: #000;">&#91;</span><span style="color: #cc66cc;">4</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$formated_log</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'time'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$logs</span><span style="color: #000;">&#91;</span><span style="color: #cc66cc;">5</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$formated_log</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'timezone'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$logs</span><span style="color: #000;">&#91;</span><span style="color: #cc66cc;">6</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$formated_log</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'method'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$logs</span><span style="color: #000;">&#91;</span><span style="color: #cc66cc;">7</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$formated_log</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'path'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$logs</span><span style="color: #000;">&#91;</span><span style="color: #cc66cc;">8</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$formated_log</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'protocal'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$logs</span><span style="color: #000;">&#91;</span><span style="color: #cc66cc;">9</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$formated_log</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'status'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$logs</span><span style="color: #000;">&#91;</span><span style="color: #cc66cc;">10</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$formated_log</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'bytes'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$logs</span><span style="color: #000;">&#91;</span><span style="color: #cc66cc;">11</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$formated_log</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'referer'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$logs</span><span style="color: #000;">&#91;</span><span style="color: #cc66cc;">12</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #000088;">$formated_log</span><span style="color: #000;">&#91;</span><span style="color: #0000ff;">'agent'</span><span style="color: #000;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$logs</span><span style="color: #000;">&#91;</span><span style="color: #cc66cc;">13</span><span style="color: #000;">&#93;</span><span style="color: #339933;">;</span>
			<span style="color: #22f;">return</span> <span style="color: #000088;">$formated_log</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// return the array of info</span>
		<span style="color: #000;">&#125;</span>
		<span style="color: #22f;">else</span>
		<span style="color: #000;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">badRows</span><span style="color: #339933;">++;</span> <span style="color: #666666; font-style: italic;">// if the row is not in the right format add it to the bad rows</span>
			<span style="color: #22f;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #000;">&#125;</span>
	<span style="color: #000;">&#125;</span>
<span style="color: #000;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>And here&#8217;s an example of how to use it:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> apache_log_parser<span style="color: #000;">&#40;</span><span style="color: #000088;">$d</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">path</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'/'</span><span style="color: #339933;">.</span><span style="color: #000088;">$entry</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Create an apache log parser</span>
<span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">filters</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span>
	<span style="color: #0000ff;">'path'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span><span style="color: #000;">&#40;</span><span style="color: #0000ff;">'regex'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'/^.*\.(FLV|flv)$/'</span><span style="color: #000;">&#41;</span> <span style="color: #666666; font-style: italic;">//pull only flv files</span>
<span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$data</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$data</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getData</span><span style="color: #000;">&#40;</span><span style="color: #000;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>A couple things to note about this script though:</p>
<p>1. The regex and parsing was pretty stolen from the <a href="http://phpclasses.ranchoweb.com/browse/package/2596.html" onclick="return TrackClick('http%3A%2F%2Fphpclasses.ranchoweb.com%2Fbrowse%2Fpackage%2F2596.html','Apache+Log+Parser+on+PHPClasses.org')" target="_blank">Apache Log Parser on PHPClasses.org</a>.<br />
2. Without filters the script is pretty memory intensive. My needs don&#8217;t require anything client facing but heed my adivice; Don&#8217;t use this on a public web server. </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2010/01/parse-apache-log-files-with-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>What Does Zend Server CE Have to Offer?</title>
		<link>http://blog.ericlamb.net/2009/07/what-does-zend-server-ce-have-to-offer/</link>
		<comments>http://blog.ericlamb.net/2009/07/what-does-zend-server-ce-have-to-offer/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 13:00:39 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Rant]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[IIS]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[zend server]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=1726</guid>
		<description><![CDATA[Since I had to setup a whole new computer I decided to move away from the IIS experiment I&#8217;ve been working on for the last year and try something a little different. I&#8217;d heard about Zend Server CE before but after a failed attempt to get it working a few months ago, because of IIS [...]]]></description>
			<content:encoded><![CDATA[<p>Since I had to setup a whole new computer I decided to move away from the IIS experiment I&#8217;ve been working on for the last year and try something a little different. I&#8217;d heard about <a title="Zend Server" href="http://www.zend.com/en/products/server-ce/downloads?hpb=server_CE_Download" onclick="return TrackClick('http%3A%2F%2Fwww.zend.com%2Fen%2Fproducts%2Fserver-ce%2Fdownloads%3Fhpb%3Dserver_CE_Download','Zend+Server')" target="_blank">Zend Server CE</a> before but after a failed attempt to get it working a few months ago, because of IIS ironically enough, I hadn&#8217;t really given it the attention I thought it deserved. After having played with it for about a week I have to say I&#8217;m completely&#8230; <em>underwhelmed</em>.</p>
<div id="attachment_1730" class="wp-caption aligncenter" style="width: 207px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/05/failed-to-login.jpg" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F05%2Ffailed-to-login.jpg','Failed+to+Login')"><img class="size-medium wp-image-1730" title="Failed to Login" src="http://blog.ericlamb.net/wp-content/uploads/2009/05/failed-to-login-197x300.jpg" alt="Failed to Login" width="197" height="300" /></a><p class="wp-caption-text">Failed to Login</p></div>
<p>Zend Server is supposed to be a complete Web Application Server that is purpose built for php development. It includes application monitoring, problem root cause analysis and and extended caching capabilities. Pretty enticing really.</p>
<p>Unfortunately, Zend Server <em>CE</em> doesn&#8217;t include any of the above bells and whistles. Instead, it&#8217;s a stripped down version that appears to just match the features and functionality of <a title="XAMP" href="http://www.apachefriends.org/en/xampp-windows.html" onclick="return TrackClick('http%3A%2F%2Fwww.apachefriends.org%2Fen%2Fxampp-windows.html','XAMP')" target="_blank">XAMP</a> or <a title="WAMP" href="http://www.wampserver.com/en/" onclick="return TrackClick('http%3A%2F%2Fwww.wampserver.com%2Fen%2F','WAMP')" target="_blank">WAMP</a> (Apache, php and mysql wrapped in a nice little installer for Windows).</p>
<p>I&#8217;ve used both used both XAMP and WAMP and, with little exception, I&#8217;ve always wished I&#8217;d gone with a manual installation instead. It&#8217;s not that they&#8217;re bad programs, it&#8217;s nice that they&#8217;re available for newbies, but my needs aren&#8217;t easy to package up in a &#8220;one size fits all&#8221; package. I like to try new things and experiment and sometimes what I want to do isn&#8217;t easy without breaking something. Admittedly, I haven&#8217;t tried to use any one size package for a few years so this may not be the case anymore.</p>
<p>Either way though, I know I have a bias; I might even be a bit of a snob about the issue. Totally possible.</p>
<p>That being said, after installing Zend Server CE, which went very smoothly actually, I was confronted with what appeared to be an incomplete installation of php; php-win just didn&#8217;t work. It did nothing in fact; I couldn&#8217;t get it to do a damn thing. Since I do a little maintenance scripting with php-cli (and php-win.exe is essential on Windows) this was a pretty big issue.</p>
<p>On top of that, I just couldn&#8217;t figure out how to modify the &#8211;configure options so changing the setup was obviously going to be an issue. I don&#8217;t know if I&#8217;m an idiot but I just couldn&#8217;t figure it out.</p>
<p>Then the let down happened; I was under the impression that there were going to be some cool profiling toys to play with. Instead, there&#8217;s a web GUI for configuring PHP, which is pretty nice I guess, but for me, it&#8217;s just easier to edit php.ini directly than navigate through a web interface. Kind of useless. What with the integration with Zend Debugger I was really expecting <em>more.</em></p>
<p>Ultimately, it seems that if you&#8217;re a complete newbie to php Zend Server CE is a worthwhile fit but if you actually know what you&#8217;re doing you&#8217;re still better off setting up a development environment manually.</p>
<p>This is pretty disappointing. A product from Zend, that&#8217;s supposed to ease the pain of php development being released to the community, offering nothing more than you could already get from a dozen other programs kind of seems like posturing. I understand the desire to have a demo of a paid product but it should, you know, <em>be different</em>.</p>
<p>A good change I&#8217;d like to see would be to include some of the more advanced features like the Application problem diagnostics and the Application monitoring (alerting) functionality in the CE version. It would benefit the community far better than the current version.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2009/07/what-does-zend-server-ce-have-to-offer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>lighttpd. use it</title>
		<link>http://blog.ericlamb.net/2009/01/lighttpd-use-it/</link>
		<comments>http://blog.ericlamb.net/2009/01/lighttpd-use-it/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 06:46:15 +0000</pubDate>
		<dc:creator>Eric Lamb</dc:creator>
				<category><![CDATA[Servers]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[lighttpd]]></category>

		<guid isPermaLink="false">http://blog.ericlamb.net/?p=23</guid>
		<description><![CDATA[I&#8217;ve been using lighttpd as my main production web server since the summer of 2007. I first heard about lighttpd from a server administrator I was working with on a project a few years earlier but since my clients weren&#8217;t getting traffic that Apache couldn&#8217;t handle I didn&#8217;t really pay it too much attention. As [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using <a href="http://www.lighttpd.net/" onclick="return TrackClick('http%3A%2F%2Fwww.lighttpd.net%2F','lighttpd')" title="lighttpd" target="_blank">lighttpd</a> as my main production web server since the summer of 2007. I first heard about lighttpd from a server administrator I was working with on a project a few years earlier but since my clients weren&#8217;t getting traffic that <a href="http://www.apache.org/" onclick="return TrackClick('http%3A%2F%2Fwww.apache.org%2F','Apache')" title="Apache" target="_blank">Apache</a> couldn&#8217;t handle I didn&#8217;t really pay it too much attention. As far as I was concerned it was a cool idea, building a better webserver, but since lighttpd was so new and support and documentation being a little sparce, compared to, say, Apache&#8217;s documentation, all using lighttpd meant was that I had to stay away from Apache specific functionality and I&#8217;d be ok. </p>
<div id="attachment_609" class="wp-caption aligncenter" style="width: 259px"><img src="http://blog.ericlamb.net/wp-content/uploads/2009/01/light_logo.png" alt="lighttpd" title="lighttpd" width="249" height="239" class="size-full wp-image-609" /><p class="wp-caption-text">lighttpd</p></div>
<p>Fast forward a couple years and I&#8217;m working on projects that Apache is really struggling with. The point of removing Apache from my toolbox started because one of our projects at StreetWise, the official community for one of our biggest client&#8217;s programs, was having serious load issues. The site was <em>very</em> popular, getting over 2,000,000 hits a day, and Apache was having a hard time dealing. Here we were with 8 web servers, on a load balancer, 3 DB servers, and all of the web servers were just getting hammered; it was cascading, where one by one the servers would go into swap and all traffic would be shifted to a different server, only to have the same thing happen again until all servers died. It was a very, <em>very</em>, stressful time for my team and I.</p>
<p>We tried configuring the hell out of Apache, upgrading the server&#8217;s RAM and adding additional CPUs but finally came to realize that continuing with Apache meant we&#8217;d just have to get more servers. Apache can only handle so many users at one time, like all webservers really, so we needed a web server that could handle more users at one time. It&#8217;s a pretty basic  While adding additional servers to a project is cheaper than throwing people at it, if it&#8217;s a software issue, there&#8217;s additional costs with hardware in my team especially because we manage the servers ourselves.</p>
<p>This wasn&#8217;t good; it meant explaining to the client that we would need more money outside of our projections, which is embarrassing and, worse, my team would have to manage <em>more</em> servers (we were already managing 18 in total at the time).</p>
<p>It was at this time that lighttpd came back into play. Since Apache wasn&#8217;t working out so hot in the load we were under it had to be replaced. I remembered how lighttpd was started as a proof of concept for the <a href="http://www.kegel.com/c10k.html" onclick="return TrackClick('http%3A%2F%2Fwww.kegel.com%2Fc10k.html','C10K+Problem')" title="C10K Problem" target="_blank">C10K</a> problem and had some pretty <a href="http://www.lighttpd.net/benchmark" onclick="return TrackClick('http%3A%2F%2Fwww.lighttpd.net%2Fbenchmark','Lighttpd+Benchmarks')" title="Lighttpd Benchmarks" target="_blank">impressive benchmarks</a> so I started researching more about it. </p>
<p>While lighttpd&#8217;s penetration wasn&#8217;t even a blip compared to Apache or IIS we installed it on a one of our dev servers and started testing it.<br />
<div id="attachment_621" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.ericlamb.net/wp-content/uploads/2009/01/overallc.jpg" onclick="return TrackClick('http%3A%2F%2Fblog.ericlamb.net%2Fwp-content%2Fuploads%2F2009%2F01%2Foverallc.jpg','lighttpd+Overall+Usage')"><img src="http://blog.ericlamb.net/wp-content/uploads/2009/01/overallc-300x163.jpg" alt="lighttpd Overall Usage" title="lighttpd Overall Usage" width="300" height="163" class="size-medium wp-image-621" /></a><p class="wp-caption-text">lighttpd Overall Usage</p></div></p>
<p>Installing lighttpd was pretty straightforward though setting up php to run in fast-cgi mode was a little more challenging than usual. Right away, one of the biggest challenges was the configuration though. After using Apache for, well, <em>forever</em> really, moving to how lighttpd was configured was pretty difficult.</p>
<p><em>lighttpd.conf example</em></p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">$HTTP[<span style="color: #7f007f;">&quot;host&quot;</span>] =~ <span style="color: #7f007f;">&quot;(www.)?your-domain.com&quot;</span> {
&nbsp;
  server.document-root = <span style="color: #7f007f;">&quot;/www/your-domain.com/html&quot;</span>
&nbsp;
<span style="color: #adadad; font-style: italic;">#### auth module</span>
<span style="color: #adadad; font-style: italic;">## read authentication.txt for more info</span>
auth.backend               = <span style="color: #7f007f;">&quot;htpasswd&quot;</span>
auth.backend.htpasswd.userfile = <span style="color: #7f007f;">&quot;/www/your-domain.com/.htpasswd&quot;</span>
<span style="color: #adadad; font-style: italic;">#auth.backend.plain.groupfile = &quot;lighttpd.group&quot;</span>
auth.<span style="color: #22f;">require</span>               = ( <span style="color: #7f007f;">&quot;/&quot;</span> =&gt;
                               (
                                 <span style="color: #7f007f;">&quot;method&quot;</span>  =&gt; <span style="color: #7f007f;">&quot;basic&quot;</span>,
                                 <span style="color: #7f007f;">&quot;realm&quot;</span>   =&gt; <span style="color: #7f007f;">&quot;Server Info&quot;</span>,
                                 <span style="color: #7f007f;">&quot;require&quot;</span> =&gt; <span style="color: #7f007f;">&quot;valid-user&quot;</span>
                               )
                             )
&nbsp;
}</pre></div></div>

<p>Compare the above to the below.<br />
<em>httpd.conf example</em></p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">VirtualHost</span> *&gt;
    <span style="color: #22f;">ServerName</span> your-domain.com
    <span style="color: #22f;">DocumentRoot</span> /www/your-domain.com/html
    <span style="color: #22f;">ServerAdmin</span> contact@your-domain.com
    &lt;<span style="color: #000000; font-weight:bold;">IfModule</span> mod_suphp.c&gt;
        suPHP_UserGroup nobody nobody
    &lt;/<span style="color: #000000; font-weight:bold;">IfModule</span>&gt;
&lt;/<span style="color: #000000; font-weight:bold;">VirtualHost</span>&gt;</pre></div></div>

<p>Right away, you can see how Apache and Lighttpd have different philosophies on layout and structure. Apache takes an XML structure for their configuration files while lighttpd formats its configurations like an array. </p>
<p>Anyway, after familiarizing ourselves in how lighttpd was configured we started the process of moving all the production servers away from Apache over to lighttpd. We went one server at a time, installing lighttpd, configuring, benchmarking and then changing the server&#8217;s init so lighttpd was started and Apache wasn&#8217;t. All told the process took about a week.</p>
<p>Since then, I haven&#8217;t had a single issue related to load on one of lighttpd boxes. If you&#8217;re serious about performance and care about how your projects function check out lighttpd ASAP.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ericlamb.net/2009/01/lighttpd-use-it/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
