<?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>A Fool's Wisdom &#187; php</title>
	<atom:link href="http://foolswisdom.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://foolswisdom.com</link>
	<description>A fool and his blog are soon parted.</description>
	<lastBuildDate>Mon, 12 Dec 2011 22:39:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>wp-content in Code is a Tell for Common WordPress Coding Mistakes</title>
		<link>http://foolswisdom.com/wp-content-in-code-common-mistakes/</link>
		<comments>http://foolswisdom.com/wp-content-in-code-common-mistakes/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 18:59:39 +0000</pubDate>
		<dc:creator>Lloyd</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Absolution Paths]]></category>
		<category><![CDATA[ABSPATH]]></category>
		<category><![CDATA[bloginfo()]]></category>
		<category><![CDATA[Duane Storey]]></category>
		<category><![CDATA[get_stylesheet_directory()]]></category>
		<category><![CDATA[get_stylesheet_directory_uri()]]></category>
		<category><![CDATA[get_stylesheet_uri()]]></category>
		<category><![CDATA[Mark Jaquith]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Plugin Development]]></category>
		<category><![CDATA[Relative Paths]]></category>
		<category><![CDATA[STYLESHEETPATH]]></category>
		<category><![CDATA[TEMPLATEPATH]]></category>
		<category><![CDATA[URLs]]></category>
		<category><![CDATA[Will Norris]]></category>
		<category><![CDATA[WordPress Plugin Checker]]></category>
		<category><![CDATA[WordPress Theme Development]]></category>
		<category><![CDATA[WordPress.com]]></category>
		<category><![CDATA[wp-content]]></category>
		<category><![CDATA[WP_CONTENT_DIR]]></category>

		<guid isPermaLink="false">http://foolswisdom.com/?p=1813</guid>
		<description><![CDATA[Regularly while reviewing themes and plugins, I&#8217;ll see URLs or paths that include &#8216;wp-content&#8217;. This is a often a hint of a WordPress coding mistake. Consider this simple example: &#60;link rel="stylesheet" href="http://example.com/wp-content/themes/default/style-ie.css" type="text/css" media="screen" /&#62; If as part of a &#8230; <a href="http://foolswisdom.com/wp-content-in-code-common-mistakes/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Regularly while reviewing themes and plugins, I&#8217;ll see URLs or paths that include &#8216;wp-content&#8217;. This is a often a hint of a WordPress coding mistake.</p>
<p>Consider this simple example:<br />
<code>&lt;link rel="stylesheet" href="http://example.com/wp-content/themes/default/style-ie.css" type="text/css" media="screen" /&gt;</code></p>
<p>If as part of a migration or server change, WordPress ends up in a sub-directory this will break.</p>
<p>For file system based access, if I see <code>ABSPATH . '/wp-content/</code> &#8230; things are likely OK, though if <code><a href="http://codex.wordpress.org/Editing_wp-config.php#Moving_wp-content">WP_CONTENT_DIR</a></code> or similar are changed, this will also break.</p>
<p>I&#8217;m tempted to use the constant <code>STYLESHEETPATH</code> or is it <code>TEMPLATEPATH</code>? But, those are static variables initialized early in the WordPress run.</p>
<p>I&#8217;ve been meaning to write this article for a while. Serendipitously, when I went to write a first draft of it, <a href="http://markjaquith.com/">Mark Jaquith</a>&#8216;s had just published &#8220;<a href="http://markjaquith.wordpress.com/2009/05/04/force-css-changes-to-go-live-immediately/">Force CSS changes to “go live” immediately</a>&#8220;.</p>
<p>In the comments, <a href="http://op111.net/">demetris</a> <a href="http://markjaquith.wordpress.com/2009/05/04/force-css-changes-to-go-live-immediately/#comment-92283">suggests</a> using STYLESHEETPATH, but <a href="http://willnorris.com/">Will Norris</a> quickly <a href="http://markjaquith.wordpress.com/2009/05/04/force-css-changes-to-go-live-immediately/#comment-92284">points out</a> &#8220;sure, but you still have the same problem of bypassing any plugins that may be using the ’stylesheet_directory’ hook to pull the stylesheet from some place else entirely.&#8221;</p>
<p>Mark&#8217;s solution beautiful illustrates how to get the the URL location of the theme&#8217;s files and also directly the URL for the main stylesheet style.css:</p>
<p><code>&lt;link rel="stylesheet" href="&lt;?php <strong>bloginfo('stylesheet_url')</strong>; echo '?' . filemtime( <strong>get_stylesheet_directory()</strong> . '/style.css'); ?&gt;" type="text/css" media="screen, projection" /&gt;</code></p>
<p>What Will describes is exactly what WordPress.com depends on. We have a similar, but much more complex solution to deal with the CSS in the content delivery network (CDN) going stale on updates, and also some web browser&#8217;s with their funky caches not keeping up. Our solution is both for WordPress&#8217;s front end and dashboard (also dealing with the various ways CSS can be called or @imported).</p>
<p>I do have one niggle about Mark&#8217;s solution, and it&#8217;s the same with most WordPress code out there, the use of <code>bloginfo()</code>. Strings within strings within strings within strings give me headache, so to ease readability and make it more verbose replace:</p>
<p><code>bloginfo('stylesheet_url');</code> with<code><br />
echo get_stylesheet_uri();</code></p>
<p><code>bloginfo('stylesheet_directory');</code> with<br />
<code>echo get_stylesheet_directory_uri();</code></p>
<p>If you look up in the <a href="http://codex.wordpress.org/">codex</a> <code>get_stylesheet_directory()</code> you&#8217;ll see that would be the file system path, which is confusing given the behavior of <code>bloginfo('stylesheet_directory');</code> returning the URL. This presents another reason why I favor the consistency of always using the specific getter function calls. Also, when I&#8217;m using <code>bloginfo()</code> calls, I have a tendency to get in a mind set where I think I&#8217;m directly retrieving the option in the database (accessing directly the info shown in <code>wp-admin/options.php</code>). By using the specific getter function, I remember that there are hooks (actions, filters) that might be triggered.</p>
<p>Some of the other areas, I see <code>wp-content</code> is in CSS style sheets themselves. <strong>Relative paths</strong> are almost always the correct solution.</p>
<p>Far more painful for me are the plugins that assume where plugins are, because this can take quite a bit of debugging to unwind the assumptions.</p>
<p>That is a topic for me to postulate on another day. Will has written the very relevant &#8220;<a href="http://willnorris.com/2009/06/wordpress-plugin-pet-peeve-2-direct-calls-to-plugin-files">WordPress Plugin Pet Peeve #2: Direct Calls to Plugin Files</a>&#8220;. <a href="http://www.duanestorey.com/">Duane Storey</a> has taken a crack at a &#8220;<a href="http://www.duanestorey.com/blog/2009/wordpress-plugin-checker/">WordPress Plugin Checker</a>&#8220;  for these and other common problems (which I&#8217;m certain he would enjoy feedback on).</p>
]]></content:encoded>
			<wfw:commentRss>http://foolswisdom.com/wp-content-in-code-common-mistakes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress.com&#8217;s Job System &#8211; Cron for PHP in Distributed Environment</title>
		<link>http://foolswisdom.com/cron-for-php-in-distributed-environment/</link>
		<comments>http://foolswisdom.com/cron-for-php-in-distributed-environment/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 23:21:23 +0000</pubDate>
		<dc:creator>Lloyd</dc:creator>
				<category><![CDATA[Automattic]]></category>
		<category><![CDATA[cron-like]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress.com]]></category>

		<guid isPermaLink="false">http://foolswisdom.com/?p=1948</guid>
		<description><![CDATA[Colleague Demitrious Kelly (meech, Apokalyptik) earlier this month open sourced the (Unix process) jobs system he (primarily) has been developing for WordPress.com. Not that I really understand it, but &#8220;jobs&#8221; is described as A fast, distributed, horizontally scalable system built &#8230; <a href="http://foolswisdom.com/cron-for-php-in-distributed-environment/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://automattic.com/">Colleague</a> <a href="http://blog.apokalyptik.com/">Demitrious Kelly</a> (meech, Apokalyptik) earlier this month open sourced the (Unix process) jobs system he (primarily) has been developing for WordPress.com. Not that I really understand it, but &#8220;<a href="http://code.trac.wordpress.org/browser/jobs">jobs</a>&#8221; is described as</p>
<blockquote><p>A fast, distributed, horizontally scalable system built upon linux, php5.2, and mysql 5.1 wherein work can be stored in a database, and processed outside the flow of script execution. Examples of common things that are part of script execution but not necessary to the rendering of the response to the user might be spam scanning, statistical analysis, email notification sending, processing input data, etc. Also included is an equally distributed cron mechanism to remove single servers as a point of failure for scheduled jobs.</p></blockquote>
<p>There are a lot of terms I like in there like fast, distributed, horizontally scalable, scheduled. It could probably benefit from robust and fault tolerant. Any others?</p>
<p>Anyway, this crontab-like system for PHP scripts is an essential part of our WordPress.com infrastructure, and I&#8217;m really excited to see it open sourced!</p>
<p>Check out <a href="http://code.trac.wordpress.org/">code.trac.wordpress.org </a>for other pieces of our puzzle that don&#8217;t have pretty project pages.</p>
]]></content:encoded>
			<wfw:commentRss>http://foolswisdom.com/cron-for-php-in-distributed-environment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning by doing something else</title>
		<link>http://foolswisdom.com/learning-by-doing-something-else/</link>
		<comments>http://foolswisdom.com/learning-by-doing-something-else/#comments</comments>
		<pubDate>Tue, 24 Feb 2009 21:28:36 +0000</pubDate>
		<dc:creator>Lloyd</dc:creator>
				<category><![CDATA[Learning]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://foolswisdom.com/?p=1644</guid>
		<description><![CDATA[There is a small project that I&#8217;m working on with a friend, and since for years I&#8217;ve wanted to try Python&#8230; I find two of the greatest assistants in learning and developing expertise in something are: Helping someone else (teaching). &#8230; <a href="http://foolswisdom.com/learning-by-doing-something-else/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div class="wp-caption alignright" style="width: 181px"><a href="http://flickr.com/photos/bootbearwdc/515399703/"><img title="Dr. Andrei Dmitrievich Sakharov" src="http://farm1.static.flickr.com/211/515399703_72ece0c2d1_m.jpg" alt="Dr. Andrei Dmitrievich Sakharov" width="171" height="240" /></a><p class="wp-caption-text">Dr. Andrei Dmitrievich Sakharov Sculpture photo by Flickr user dbking. Andrei Dmitrievich Sakharov (May 21, 1921 – December 14, 1989) was an eminent Soviet nuclear physicist, dissident and human rights activist. Sakharov was an advocate of civil liberties and reforms in the Soviet Union. He was awarded the Nobel Peace Prize in 1975. (wikipedia)</p></div>
<p>There is a small project that I&#8217;m working on with a friend, and since for years I&#8217;ve wanted to try Python&#8230;</p>
<p>I find two of the greatest assistants in learning and developing expertise in something are:</p>
<ul>
<li>Helping someone else (teaching).</li>
<li>Using something else (compare).</li>
</ul>
<p>Experimenting with something else helps me take the emotions and religion out of what I&#8217;m developing expertise in. It lends to a pragmatic foundation and helps be able to speak to another audience.</p>
<p>So while I work on this Python project, I won&#8217;t feel like I&#8217;m cheating on PHP and WordPress. Instead I&#8217;m continuing my learning about both and will be a better representative of both.</p>
]]></content:encoded>
			<wfw:commentRss>http://foolswisdom.com/learning-by-doing-something-else/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Mac, WordPress: &#8220;Error establishing a database connection&#8221;</title>
		<link>http://foolswisdom.com/mac-wordpress-error-establishing-a-database-connection/</link>
		<comments>http://foolswisdom.com/mac-wordpress-error-establishing-a-database-connection/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 17:20:58 +0000</pubDate>
		<dc:creator>Lloyd</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://foolswisdom.com/?p=1283</guid>
		<description><![CDATA[If you get &#8220;Error establishing a database connection&#8221; when trying to set up WordPress.org on your Mac, are sure that the database name (DB_NAME), username (DB_USER) and password (DB_PASSWORD) are correct, the solution is very likely that you need to &#8230; <a href="http://foolswisdom.com/mac-wordpress-error-establishing-a-database-connection/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>If you get &#8220;Error establishing a database connection&#8221; when trying to set up <a href="http://wordpress.org/">WordPress.org</a> on your Mac, are sure that the database name (DB_NAME), username (DB_USER) and password (DB_PASSWORD) are correct, the solution is very likely that you need to set <code>mysql.default_socket = /tmp/mysql.sock</code> in <code>/etc/php.ini</code>.</p>
<p><span id="more-1283"></span>I read on the WordPress Support forums &#8220;<a href="http://wordpress.org/support/topic/160658 ">Error establishing a database connection on OS X 10.5</a>&#8221; where jonokane had the novel solution of changing the database host (DB_HOST) to capital L, &#8216;Localhost&#8217;.</p>
<p>mrogers writes that &#8220;This is definitely a bug in WordPress 2.5, because every other web app I have running on this machine uses &#8220;localhost&#8221; and it connects to the MySQL server just fine.&#8221;</p>
<p>The problem can be isolated to the PHP function mysql_connect() and its error return value is being suppressed:</p>
<p><code>Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/mysql/mysql.sock'</code></p>
<p>There is quite a bit of misinformation about what the problem and solution out there. The Apple doc &#8220;<a href="http://docs.info.apple.com/article.html?artnum=302977">Mac OS X Server 10.4.4: Improvements to Apache/PHP/MySQL interaction</a>&#8221; from January 2006 gives clues as to the problem. On Server, a custom MySQL is included and the doc includes:</p>
<blockquote><p>If you have downloaded and installed MySQL yourself but are using the pre-installed version of PHP, note that your custom version of MySQL might be configured to use the old MySQL socket location, /tmp/mysql.sock. The version of PHP in this software update uses the newer location /var/mysql/mysql.sock by default.</p></blockquote>
<p>The problem with Apple using the &#8220;newer location&#8221; is that MySQL hasn&#8217;t had a major release since 2005 and so their packages don&#8217;t use the newer location, and there is no custom MySQL package for the rest of us. We have to download the regular MySQL 5 package from MySQL.com.</p>
<p>Jonokane&#8217;s novel solution likely works because instead of using a socket for the local connection, it attempts a TCP/IP connection, and &#8216;Localhost&#8217; resolves to &#8216;localhost&#8217;. That will only solve the problem for WordPress though, and you would have the same problem with other PHP applications.</p>
<p>The correct solution is to:</p>
<p><code>$sudo cp /etc/php.ini.default /etc/php.ini<br />
$sudo chmod +w /etc/php.ini</code></p>
<p>And in your favorite editor find the line that starts <code>mysql.default_socket</code> and update it to read</p>
<p><code>mysql.default_socket = /tmp/mysql.sock</code></p>
<p>Now restart Apache, and it should be golden.</p>
<p>You won&#8217;t encounter this problem if you are using the packages from <a href="http://www.macports.org/">Mac Ports</a> or <a href="http://www.mamp.info/">MAMP</a>, but those would be their own adventures.</p>
]]></content:encoded>
			<wfw:commentRss>http://foolswisdom.com/mac-wordpress-error-establishing-a-database-connection/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Congratulations to the Drupal 6 team!</title>
		<link>http://foolswisdom.com/congratulations-to-the-drupal-6-team/</link>
		<comments>http://foolswisdom.com/congratulations-to-the-drupal-6-team/#comments</comments>
		<pubDate>Thu, 14 Feb 2008 21:24:03 +0000</pubDate>
		<dc:creator>Lloyd</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[Dave Olson]]></category>
		<category><![CDATA[DaveO]]></category>
		<category><![CDATA[drupal]]></category>
		<category><![CDATA[Drupal 6.0]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Raincity Studio]]></category>

		<guid isPermaLink="false">http://foolswisdom.com/?p=750</guid>
		<description><![CDATA[Drupal 6.0 was released yesterday. DaveO of Raincity Studio writes, &#8220;I think these changes (while admittedly lacking in really exciting talking points for the non-geeks) reflect an increased focus on usability and offer ways to do more with less.&#8221; Congratulations &#8230; <a href="http://foolswisdom.com/congratulations-to-the-drupal-6-team/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://drupal.org/drupal-6.0">Drupal 6.0</a> was released yesterday. <a href="http://uncleweed.net/">DaveO</a> of <a href="http://www.raincitystudios.com/">Raincity Studio</a> <a href="http://www.raincitystudios.com/blogs-and-pods/daveo/drupal-6-content-management-system-released">writes</a>, &#8220;I think these changes (while admittedly lacking in really exciting talking points for the non-geeks) reflect an increased focus on usability and offer ways to do more with less.&#8221;</p>
<p>Congratulations to the Drupal community!</p>
]]></content:encoded>
			<wfw:commentRss>http://foolswisdom.com/congratulations-to-the-drupal-6-team/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>I Want To Be PHP Dangerous</title>
		<link>http://foolswisdom.com/i-want-to-be-php-dangerous/</link>
		<comments>http://foolswisdom.com/i-want-to-be-php-dangerous/#comments</comments>
		<pubDate>Wed, 29 Aug 2007 23:31:12 +0000</pubDate>
		<dc:creator>Lloyd</dc:creator>
				<category><![CDATA[Collaborating]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Work]]></category>
		<category><![CDATA[development environment]]></category>
		<category><![CDATA[ide]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming language]]></category>
		<category><![CDATA[small company]]></category>
		<category><![CDATA[startup]]></category>
		<category><![CDATA[web programming]]></category>

		<guid isPermaLink="false">http://foolswisdom.com/i-want-to-be-php-dangerous/</guid>
		<description><![CDATA[Although, I&#8217;m surrounded by PHP masters, and PHP programming isn&#8217;t in my job description, I want to be at least &#8220;PHP dangerous&#8221;. The first lessons if you want to reach your goals in a small company is that you have &#8230; <a href="http://foolswisdom.com/i-want-to-be-php-dangerous/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Although, I&#8217;m <a href="http://wordpress.org/about/">surrounded</a> <a href="http://automattic.com/about/">by</a> PHP masters, and PHP programming isn&#8217;t in my job description, I want to be at least &#8220;PHP dangerous&#8221;.</p>
<p><span id="more-575"></span>The first lessons if you want to reach your goals in a small company is that you have to be willing to do every job, and will probably have to do many of them. You have to be flexible, there is no organizational hierarchy to assign the work to.</p>
<p>So although not in my job description doesn&#8217;t include PHP programming, it will help me be a better participant in <a href="http://automattic.com/">the company</a> and in <a href="http://automattic.com/projects/">the products</a> I care most about.</p>
<p>Discovering and isolating problems comes fairly naturally to me, as does duplicating other&#8217;s results, but turning a coding problem into a solution no longer does &#8212; I&#8217;m long out of practice, and that practice never included PHP.</p>
<p>Sure, I can fix a typo or add a token or two of code, but I&#8217;m long out of practice in creating real solutions. Getting there would give me a much better understanding of the WordPress code, and ultimately the experience.</p>
<p>I have my PHP book, <a href="http://www.amazon.com/gp/product/0672326728?ie=UTF8&amp;tag=foolswisdomco-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0672326728">PHP and MySQL Web Development</a> by Luke Willing and Laura Thomson (purple spine, aquaducts on cover)<img src="http://www.assoc-amazon.com/e/ir?t=foolswisdomco-20&amp;l=as2&amp;o=1&amp;a=0672326728" style="border: medium none  ! important; margin: 0px ! important" border="0" height="1" width="1" />, have plenty of small projects on my mind, and will find the time, but first I feel like I want to find myself a crutch of a good PHP development environment.</p>
]]></content:encoded>
			<wfw:commentRss>http://foolswisdom.com/i-want-to-be-php-dangerous/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

