<?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>pixelnix.com &#187; PHP</title>
	<atom:link href="http://pixelnix.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://pixelnix.com</link>
	<description></description>
	<lastBuildDate>Fri, 18 Jun 2010 20:10:37 +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>Custom logging to a database with PHP and Apache</title>
		<link>http://pixelnix.com/custom-logging-to-a-database-with-php-and-apache/</link>
		<comments>http://pixelnix.com/custom-logging-to-a-database-with-php-and-apache/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 19:20:21 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://pixelnix.com/?p=84</guid>
		<description><![CDATA[My organization needed a way to create several types of persistent database-stored logs for our PHP website, where each log entry would record which user was requesting the resource.  We decided we would try for a solution that did not require us to do a database insert for every page view, for obvious reasons.  Here [...]]]></description>
			<content:encoded><![CDATA[<p>My organization needed a way to create several types of persistent database-stored logs for our PHP website, where each log entry would record which user was requesting the resource.  We decided we would try for a solution that did not require us to do a database insert for every page view, for obvious reasons.  Here is what we came up with.  Our environment is PHP5 and Apache 2.2.</p>
<p><span id="more-84"></span>Apache&#8217;s <a href="http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#formats" target="_blank">custom log format</a> shows how to log variables from the Apache environment.  If there&#8217;s an environment variable called FOOBAR, you log it with the format string <em>%{FOOBAR}e</em>.  This is great because PHP can inject data into the Apache environment, meaning we can get more or less any data we like into an Apache custom log.</p>
<p>The first Apache configuration step was to create a custom log format that we can then apply to a logfile.  We create the log format in httpd.conf.  Find the log_config_module section and add a LogFormat directive there:</p>
<pre>&lt;IfModule log_config_module&gt;
LogFormat "%t %U %D %a %{MY_UID}e" mystats
&lt;/IfModule&gt;</pre>
<p>In this example, we add a log format named &#8220;mystats&#8221; which logs these datapoints:  date/time the request was received, URL path requested, time taken to serve the request, remote client IP address, and the environment variable MY_UID.  For our purposes, we are logging these data because our aim is to keep a 7-day rolling log of webserver performance &#8211; how long it took to process each request &#8211; to monitor our servers more effectively.</p>
<p>Then we set up a custom log for our site&#8217;s vhost in httpd-vhosts.conf:</p>
<pre>&lt;VirtualHhost 192.168.100.1:80&gt;
...
CustomLog logs/mysite_custom_log mystats
...
&lt;/VirtualHost&gt;</pre>
<p>This makes Apache start logging every request to that host, in the format defined by our LogFormat directive named &#8220;mystats&#8221;.</p>
<p>The first step in PHP code, then, is to simply inject the MY_UID environment variable containing the user ID of whoever is logged in.  In our master controller there&#8217;s a check to see if the client has an authenticated session, and if they do we just add a quick call to set the environment var:</p>
<pre>apache_setenv('MY_UID', $the_current_user_id);</pre>
<p>Once this in all in place, you should be able to tail the logfile mysite_custom_log and see that requests are being logged with the requesting client&#8217;s user ID, or &#8220;-&#8221; if no user is authenticated.</p>
<p>We rotate these logs daily.  Our final step is a cron&#8217;d PHP script that runs in the wee hours, taking yesterday&#8217;s log file, iterating each line, inserting the data into a table&#8230; and we&#8217;re done!  We logged each request with how long our server processed it, and who was signed in for that request, and we did it without adding any overhead to our application.</p>
]]></content:encoded>
			<wfw:commentRss>http://pixelnix.com/custom-logging-to-a-database-with-php-and-apache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ant Tar task doesn&#8217;t care about your file permissions</title>
		<link>http://pixelnix.com/ant-tar-task-doesnt-care-about-your-file-permissions/</link>
		<comments>http://pixelnix.com/ant-tar-task-doesnt-care-about-your-file-permissions/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 16:36:23 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[Apache Ant]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://pixelnix.com/?p=55</guid>
		<description><![CDATA[According to the documentation for the Ant Tar task, the &#8220;implicit fileset&#8221; of stuff to be included in your archive can be extended &#8220;to allow control over the access mode, username and groupname.&#8221;  I guess you have to read between the lines (or go with the ol&#8217; trial by error) to find out that not only [...]]]></description>
			<content:encoded><![CDATA[<p>According to <a href="http://ant.apache.org/manual/CoreTasks/tar.html">the documentation</a> for the Ant Tar task, the &#8220;implicit fileset&#8221; of stuff to be included in your archive can be extended &#8220;to allow control over the access mode, username and groupname.&#8221;  I guess you have to read between the lines (or go with the ol&#8217; trial by error) to find out that not only does the implicit fileset provide no control over these properties of your files, it actively reverts the file permissions to some default access mode (644).  Java ftw!</p>
<p>So you are hypothetically deploying your ant-built tar&#8217;d up software release.  Let&#8217;s further say for the sake of argument that it contains some business-critical scripts that must keep their executable mode to be run from cron.  Oops, those files are no longer executable!  You will soon be disappointed at the failure of your cron job to do anything at all, and you may experience some increased email volume accompanied by mild irritation.  If this condition persists, call your doctor, or go back and RTFM again because as the docs imply, this shortcoming can be easily overcome.</p>
<p><span id="more-55"></span>Your job is to identify all the files that need to keep their mode, username, or groupname, and specify said property in a special fileset called tarfileset.  In my ant build, let&#8217;s say the build root is ${builddir} and contains 2 components called src and lib.  I&#8217;ve got one specific file src/foo/exec.sh, and a whole tree of stuff at lib/bar, that have to be executable.  I will need to call the Tar task with two tarfilesets: one to include the executables and set their mode, and a second to include everything else while excluding the executables.</p>
<p>Before:</p>
<pre>&lt;tar destfile="${buildfile.name}"
     basedir="${builddir}"
     longfile="gnu"
     includes="src/**, lib/**"/&gt;</pre>
<p>After:</p>
<pre>&lt;tar destfile="${buildfile.name}" longfile="gnu"&gt;
     &lt;tarfileset dir="${builddir}" filemode="755"&gt;
         &lt;include name="src/foo/exec.sh"/&gt;
         &lt;include name="lib/bar/**"/&gt;
     &lt;/tarfileset&gt;
     &lt;tarfileset dir="${builddir}"&gt;
         &lt;include name="src/**"/&gt;
         &lt;include name="lib/**"/&gt;
         &lt;exclude name="src/foo/exec.sh"/&gt;
         &lt;exclude name="lib/bar/**"/&gt;
     &lt;/tarfileset&gt;
&lt;/tar&gt;</pre>
<p>Works for me!</p>
]]></content:encoded>
			<wfw:commentRss>http://pixelnix.com/ant-tar-task-doesnt-care-about-your-file-permissions/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>WordPress plugins released</title>
		<link>http://pixelnix.com/wordpress-plugins-released/</link>
		<comments>http://pixelnix.com/wordpress-plugins-released/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 22:14:32 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://pixelnix.com/?p=28</guid>
		<description><![CDATA[I developed two plugins (so far) to support the new Habitat for Humanity Portland/Metro East site, and they are now listed in the WordPress Plugin Repository:

PageSpot
Media2Layout

So far today I have compulsively checked the download statistics and somehow 60+ people downloaded PageSpot within about 6 hours of it being published.  I know there are a lot [...]]]></description>
			<content:encoded><![CDATA[<p>I developed two plugins (so far) to support the new Habitat for Humanity Portland/Metro East site, and they are now listed in the <a href="http://wordpress.org/extend/plugins">WordPress Plugin Repository</a>:</p>
<ul>
<li><a href="http://wordpress.org/extend/plugins/pagespot/">PageSpot</a></li>
<li><a href="http://wordpress.org/extend/plugins/media2layout/">Media2Layout</a></li>
</ul>
<p>So far today I have compulsively checked the download statistics and somehow 60+ people downloaded PageSpot within about 6 hours of it being published.  I know there are a lot of WordPress blogs and users out there but there must be even more than I assumed.</p>
]]></content:encoded>
			<wfw:commentRss>http://pixelnix.com/wordpress-plugins-released/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
