<?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, 19 Nov 2010 22:56:45 +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>ZendFramework mystery failures caused by PHP iconv problems on Solaris</title>
		<link>http://pixelnix.com/zendframework-mystery-failures-caused-by-php-iconv-problems-on-solaris/</link>
		<comments>http://pixelnix.com/zendframework-mystery-failures-caused-by-php-iconv-problems-on-solaris/#comments</comments>
		<pubDate>Fri, 19 Nov 2010 22:55:13 +0000</pubDate>
		<dc:creator>Nick</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[iconv]]></category>
		<category><![CDATA[ZendFramework]]></category>
		<category><![CDATA[Zend_Pdf]]></category>
		<category><![CDATA[Zend_Search_Lucene]]></category>

		<guid isPermaLink="false">http://pixelnix.com/?p=95</guid>
		<description><![CDATA[Recently been dealing with mysterious failures of some ZendFramework components &#8211; namely Zend_Pdf and Zend_Search_Lucene &#8211; resulting in empty output.  For Zend_Pdf it manifested as, well, blank PDF documents.  For Zend_Search_Lucene, we got indexes full of documents with empty fields, or total failures to return query results from valid indexes.  Hopefully this post will make [...]]]></description>
			<content:encoded><![CDATA[<p>Recently been dealing with mysterious failures of some ZendFramework components &#8211; namely Zend_Pdf and Zend_Search_Lucene &#8211; resulting in empty output.  For Zend_Pdf it manifested as, well, blank PDF documents.  For Zend_Search_Lucene, we got indexes full of documents with empty fields, or total failures to return query results from valid indexes.  Hopefully this post will make it onto the internets with some of the search terms I used in a futile attempt to google up a solution, so that others can get around to solving the problem in less time than it took me.</p>
<p><span id="more-95"></span>Both sets of problems had the same cause, which I only found once I turned error_reporting up to E_ALL:  iconv() or related iconv extension functions failing to return any output, and throwing a Notice-level error usually saying something helpful like<strong> &#8220;Notice: iconv(): Wrong charset, conversion from `&#8217; to `UTF-8&#8242; is not allowed</strong>&#8221; where UTF-8 is the charset used by the Pdf or Lucene module.</p>
<p>Normally these would be caught during development, where our environments are configured to display all errors, even Notices.  But this only happens on my production servers so it was not caught until functionality started failing in production.  The moral of that sub-story:  something about Solaris maybe, I&#8217;m not sure if there even is a moral there.</p>
<p>At any rate, on the problematic Solaris servers, calling iconv() with an empty first parameter $in_charset causes the above Notice, and the function returns False.  The parameter is empty because I did not specify a value for the optional charset parameter to methods like Zend_Pdf_Page::drawText() and Zend_Search_Lucene_Field::Text().</p>
<p>Personally I think it&#8217;s a bit of lazy-ish coding in ZendFramework which allows that parameter to be empty in the first place; behavior for iconv() is not defined in the documentation for an empty input charset.  But I can&#8217;t fault them in the end since this behavior seems to be so highly isolated and isn&#8217;t even replicatable among our development and QA servers.  So far my only remedy has been to find every single place that an iconv function is used in the ZF codebase, and make sure that the variable for the input encoding, if empty, gets replaced with the value of the iconv.input_encoding config variable.</p>
<p>We&#8217;re currently using the latest &#8220;gold&#8221; version of ZF as of about 10/1/2010, and I have patched the source to eliminate the problem from both the Pdf and Search modules.  If you would like a cvs patch or gnu patch to apply those changes feel free to contact me via email.</p>
]]></content:encoded>
			<wfw:commentRss>http://pixelnix.com/zendframework-mystery-failures-caused-by-php-iconv-problems-on-solaris/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>4</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>

