<?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>DaLeeMan &#187; PHP</title>
	<atom:link href="http://www.daleeman.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.daleeman.com</link>
	<description>Not just another techblog…well, yeah it is</description>
	<lastBuildDate>Wed, 24 Feb 2010 04:18:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>Ugly PHP Code Tips</title>
		<link>http://www.daleeman.com/ugly-php-code-tips/</link>
		<comments>http://www.daleeman.com/ugly-php-code-tips/#comments</comments>
		<pubDate>Sat, 04 Oct 2008 03:27:33 +0000</pubDate>
		<dc:creator>Daleeman</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.daleeman.com/?p=20</guid>
		<description><![CDATA[I suppose this part is just a rant, but if I see one more piece of undocumented, poorly spaced, procedural lump of PHP code, I&#8217;m going to scream. I realize that much of the PHP code out there was written for free by people who were writing code just to &#8220;get the job done&#8221;&#8230;I understand [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: left;">I suppose this part is just a rant, but if I see one more piece of undocumented, poorly spaced, procedural lump of PHP code, I&#8217;m going to scream. I realize that much of the PHP code out there was written for free by people who were writing code just to &#8220;get the job done&#8221;&#8230;I understand that. Unfortunatley, when that code is published, others rely on that same code for thier job. Sure it&#8217;s free and you have a disclaimer and&#8230;whatever. There are 1000 excuses, but only one cause: Poor software engineering practices.<span id="more-20"></span></p>
<p>Perhaps due to the ubiquity of PHP among web developers, actual engineering skills may be&#8230;well&#8230;lacking. I see this a lot with many of the Drupal modules I end up having to fix to get MY job done, and I think it&#8217;s time that if you are going to call yourself a web developer, you need to flex some software engineering skills!</p>
<p style="padding-left: 30px; text-align: left;"><strong>Document Your Code</strong> - No one likes to dig through code all day and guess what they are looking at. When I say document, I dont mean write a formal SRS or SDD. I mean document EACH class, function, and major block of code in a consistent manner. Take a look at <a href="http://phpdoc.org/">phpDocumentor</a>. This package is a lot like JavaDoc, Doxygen&#8230;It makes you adhear to a certian standard, and in return you get a really nice API reference page/site.</p>
<p style="padding-left: 30px; text-align: left;"><strong>Adopt a Coding Standard/Style</strong> &#8211; A good place to start for this is the <a href="http://www.gnu.org/prep/standards/">GNU Coding Standards</a> site. While each project, group, or company will likely have thier own standards, at least this is a start.</p>
<p style="padding-left: 30px; text-align: left;"><strong>Name Things Appropriatley </strong>- This has become a huge pet-peave of mine lately: A php page with variables $a-$z. These variables mean NOTHING! For example, if I say pass in the $a variable to a function, what does that mean? How about when I call it the $StudentsArray? THAT tells you something!</p>
<p style="padding-left: 30px; text-align: left;"><strong>Start Using OOP</strong> - Object Oriented Programming (OOP) is essential in creating readable and sustainable code. While I may take some heat on this, no one can deny that PROPERLY ENGINEERED OOP code is generally much cleaner, more reusable, and much more maintainable than the comparable procedural lines.</p>
<p style="padding-left: 30px; text-align: left;"><strong>Break Your Code Up</strong> - As the author of a number of one-page scripts in the past, I can tell you that this style of coding is not the way to go. Try reading &#8211; nonetheless fixing &#8211; a huge monolithic heap of code. A great start is to simply begin grouping common functions together. Even if they are not reused, it&#8217;s MUCH easier to unit test code when it&#8217;s in small pieces.</p>
<p>It really comes down to this&#8230;If you&#8217;re going to publish code under the guise of being completely usable, be proud of what you publish! Take the time to make it right. Sure, when you&#8217;re working for free, who has the time to make things 100%? At least make the code you have readable enough so someone else can try!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daleeman.com/ugly-php-code-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using PHP to Optimize MySQL Tables</title>
		<link>http://www.daleeman.com/using-php-to-optimize-mysql-tables/</link>
		<comments>http://www.daleeman.com/using-php-to-optimize-mysql-tables/#comments</comments>
		<pubDate>Sat, 04 Oct 2008 02:39:36 +0000</pubDate>
		<dc:creator>Daleeman</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.daleeman.com/?p=8</guid>
		<description><![CDATA[Optimizing your database tables is an essential task and the performance results might amaze you. Optimization is essentially the process of defragmenting your database tables. Then you use variable-length database fields such as VARCHAR, BLOB, TEXT, or VARBINARY, defragmentation can occur when rows are deleted.  Unfortunatley, there is no &#8220;OPTIMIZE DATABASE XYZ&#8221;, instead you need to go [...]]]></description>
			<content:encoded><![CDATA[<p>Optimizing your database tables is an essential task and the performance results might amaze you. Optimization is essentially the process of defragmenting your database tables. Then you use variable-length database fields such as VARCHAR, BLOB, TEXT, or VARBINARY, defragmentation can occur when rows are deleted. <span id="more-8"></span></p>
<p>Unfortunatley, there is no &#8220;OPTIMIZE DATABASE XYZ&#8221;, instead you need to go through your tables one-by-one and optimize them using an &#8220;OPTIMIZE TABLE XYZ&#8221;.</p>
<pre lang="php" line="1">
/* optimizeTables function
*
* Input: MySQL handle, database name
*/
function optimizeTables($conn, $database) {
mysql_select_db($database, $conn);

//Get a Table List
$TableQuery = "SHOW TABLES";
$rs = mysql_query($TableQuery);

//Optimize each table in the list
while($table = mysql_fetch_array($rs)) {
$OptimizationSQL = "OPTIMIZE TABLE " . $table[0];
$rs2 = mysql_query($OptimizationSQL);
$results = mysql_fetch_row($rs2);
echo $results[0] . "   " . $results[3] . PHP_EOL;
}

//Flush table cache and close the connection
mysql_query("FLUSH TABLES");
mysql_close($conn);
}
</pre>
<p>You can also execute `myisamchk` with appropriate options from the command like for each table. In my case, I wanted to be able to integrate this into another package which has its own crontab. One more caveat: If you are using InnoDB, this process will actually increase disk useage while freeing unused space. Not sure what to do about that one&#8230;but I dont use InnoDB&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.daleeman.com/using-php-to-optimize-mysql-tables/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

