<?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>Chris JeanChris Jean &#187; Hostgator</title>
	<atom:link href="http://chrisjean.com/tag/hostgator/feed/" rel="self" type="application/rss+xml" />
	<link>http://chrisjean.com</link>
	<description>Linux, WordPress, programming, anime, and other stuff</description>
	<lastBuildDate>Mon, 16 Jan 2012 15:22:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Generating MIME Type in PHP is not Magic</title>
		<link>http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/</link>
		<comments>http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/#comments</comments>
		<pubDate>Sat, 14 Feb 2009 17:24:04 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Fileinfo]]></category>
		<category><![CDATA[Hostgator]]></category>
		<category><![CDATA[MIME]]></category>
		<category><![CDATA[mime_content_type]]></category>
		<category><![CDATA[PECL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1031</guid>
		<description><![CDATA[Sorry about the late post everyone. I had a long week and went to bed before making sure a post was queued. Hopefully you&#8217;ll forgive me. I&#8217;m working on a project where I needed to generate a MIME type given a file name. Not only did I need to create a solution that worked, I [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>Sorry about the late post everyone. I had a long week and went to bed before making sure a post was queued. Hopefully you&#8217;ll forgive me. <img src='http://chrisjean.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I&#8217;m working on a project where I needed to generate a <a href="http://en.wikipedia.org/wiki/MIME" target="_blank">MIME type</a> given a file name. Not only did I need to create a solution that worked, I also needed the solution to be compatible with PHP 4/5 and not require any additional software to be installed on the host. I thought this would be a simple matter of finding a PHP function that does this. Unfortunately, things were not as simple as this.</p>
<p><span id="more-1031"></span></p>
<h3>Problems with finfo_open</h3>
<p>I found a very helpful <a href="http://www.jellyandcustard.com/2006/01/19/php-mime-types-and-fileinfo/" target="_blank">PHP, Mime Types and Fileinfo</a> post on <a href="http://www.jellyandcustard.com/" target="_blank">Jelly and Custard</a>. The &#8220;Mime Types in PHP 4.x&#8221; seemed to be exactly what I wanted. I quickly tried it out on my server, and it failed instantly with the following error:</p>
<div class="code">PHP Fatal error: Call to undefined function finfo_open() in &#8230;.</div>
<p>Since I have PHP 5.2.6 running on my dev server, I was very confused since the post said that this was a &#8220;PHP 4.x&#8221; solution. I pulled up the PHP doc on the <a href="http://us.php.net/finfo_open" target="_blank"><code>finfo_open</code></a> function and was very surprised to see that the function is a PHP 5.3.0+ function. Fortunately, my version of PHP was just before this so that I could actually catch the error.</p>
<p>Turns out that the Jelly and Custard post points to another post, <a href="http://www.jellyandcustard.com/2006/01/19/installing-pecl-modules/" target="_blank">Installing PECL Modules</a>, where instructions are given for installing the <a href="http://pecl.php.net/package/Fileinfo" target="_blank">Fileinfo PECL Package</a>. Installing this package allows versions prior to 5.3.0 to use the <code>finfo_*</code> functions via <a href="http://pecl.php.net" target="_blank">PECL</a>.</p>
<p>This is not what I want. I&#8217;m working toward a solution that doesn&#8217;t require the installation of any additional software, and so far I&#8217;ve only seen solutions that require this. There has to be a better way.</p>
<h3>Problems with mime_content_type</h3>
<p>I then found the <a href="http://us.php.net/mime_content_type" target="_blank"><code>mime_content_type</code></a> function. This looks better. However, PHP has marked this function as <a href="http://en.wikipedia.org/wiki/Deprecation" target="_blank">deprecated</a> due to the PECL Fileinfo package. Relying on a deprecated function has numerous problems: it may throw warnings if used on versions of PHP that know the function is deprecated, most likely won&#8217;t receive any updates in the future, and could possibly be removed from future versions of PHP.</p>
<p>In addition to the deprecated issue, the <code>mime_content_type</code> function is laced with problems. In order to use the function the PHP on your system must have been built with the &#8220;<code>--with-mime-magic</code>&#8221; option. The function also relies upon the &#8220;mime_magic.magicfile&#8221; ini configuration to tell it where to find the magic file used to detect the MIME type of the file. This magic file may or may not exist/may or may not be readable.</p>
<h3>Initial Testing</h3>
<p><span class="option">These problems led to interesting results when I tested it on my CentOS dedicated and Hostgator servers.</span></p>
<p>On my CentOS 5.2 dedicated server, I have PHP 5.2.6. The PHP build on this server was not built with the &#8220;<code>--with-mime-magic</code>&#8221; option, so it doesn&#8217;t have access to the <code>mime_content_type</code> function at all. In addition to this, since the version is just before 5.3 and I haven&#8217;t installed the Fileinfo PECL package, my dedicated server does not have access to either of the official PHP solutions without installing additional software.</p>
<p>On my Hostgator shared server, I have access to PHP 5.2.8. Unlike my dedicated server, this server&#8217;s PHP build was built with the &#8220;<code>--with-mime-magic</code>&#8221; option. &#8220;This is great,&#8221; I thought. I ran a test, and the <code><code>mime_content_type</code></code> function did indeed exist. Like my CentOS server, my Hostgator server does not have the Fileinfo PECL package and does not have PHP 5.3, so the <code>finfo_*</code> functions are no go.</p>
<p>I did some more testing on my Hostgator server and was disappointed to find that the <code>mime_content_type</code> function exists yet is completely worthless. I tested file after file ranging from simple text files, to HTML documents, to a variety of image types. Every single test failed to produce a MIME type. When I say &#8220;failed&#8221;, I don&#8217;t mean that the program crashed with an error. The failure was worse than this, it simply returned an empty string to every single request.</p>
<p>I found that my Hostgator server&#8217;s PHP is set up to use the &#8220;/usr/local/apache/conf/magic&#8221; file to do it&#8217;s MIME magic. However, this file is not able to be read by my user. This means that the version of PHP might as well not have been built with the &#8220;<code>--with-mime-magic</code>&#8221; option at all.</p>
<p>It seems clear to me by now that there will not be an easy solution to this problem.</p>
<h3>Final Solution</h3>
<p>What I need is a solution that will first try to use the Fileinfo functions since they are the current standard. It will then fall back to using the <code>mime_content_type</code> function if and only if the function exists. Since the function is deprecated and PHP versions don&#8217;t actually package the replacement functions natively until 5.3.0, I need to also protect the code against conditions where neither Fileinfo nor <code>mime_content_type</code> are available. The final fallback will be manually generating the MIME type based upon an array match.</p>
<p>Using the fallback is not desirable since I probably won&#8217;t be updating the MIME types in the array very often, if at all. However, having it is better than having the code completely fail for common, present day MIME types. Hopefully, the conditions necessary to rely upon this fallback will become more and more rare as time goes on.</p>
<p>In addition to checking for the existence of the functions I&#8217;ll try to use, I need to make sure that the methods tried actually produce results. If a method fails to produce a non-empty value, I&#8217;ll move on to the next method.</p>
<h3>The Code</h3>
<p>I got the original idea for this code from a <a href="http://us.php.net/manual/en/function.mime-content-type.php#87856" target="_blank">comment by svogal</a> on the PHP doc site. I modified it to match my desired final solution.</p>
<p>The code is far to large to post here. You can download it <a href="http://chrisjean.com/wp-content/uploads/2009/02/mime_type_lib.zip" target="_blank">here</a>.</p>
<p>The array that I built for the mime types is quite large. Since I have a /etc/mime.types file (which is standard in most distros and provided by the <a href="http://en.wikipedia.org/wiki/Mailcap" target="_blank">mailcap</a> package), I simply used it to generate my array. I quickly built a Perl script that parses through the mime.types file and outputs a file containing the PHP code to create the array. This script makes it easy for me to update the array any time the mime.types file is updated.</p>
<p>You can download my Perl script <a href="http://chrisjean.com/wp-content/uploads/2009/02/generatemimetypes" target="_blank">here</a>. Simply run &#8220;perl generateMimeTypes&#8221; from the command line to build the array. The array code is put in a file called mime_type_var.code.</p>
<h3>Examples</h3>
<h4>Simple Use</h4>
<p>The code is fairly simple to use. Simply include or require the code in your own script and then call the get_file_mime_type function  by passing the file&#8217;s path as the parameter.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">require</span><span class="br0">&#40;</span> <span class="st0">&#8216;mime_type_lib.php&#8217;</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re0">$mime_type</span> = get_file_mime_type<span class="br0">&#40;</span> <span class="st0">&#8216;/home/user/public_html/image.jpg&#8217;</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&quot;$mime_type<span class="es0">\n</span>&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
</ol>
</div>
<p>This produces the following output:</p>
<div class="code">image/jpeg</div>
<p>Note that PHP&#8217;s more advanced functions have the ability to dig into the content of the file to identify the MIME type, so if your system can make use of those functions and the file is not a JPEG image, the results could vary.</p>
<h4>Using the debug Parameter</h4>
<p>I&#8217;ve also provided a debug parameter that allows you to also get information on what method was used to get the MIME type. This may be helpful if you need to determine how sure you are that the detected MIME type is accurate. When the debug parameter is used, an associative array will be returned with a <code>mime_type</code> key and a <code>method</code> key.</p>
<div class="dean_ch" style="white-space: wrap;">
<ol>
<li class="li1">
<div class="de1"><span class="kw2">&lt;?php</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">require</span><span class="br0">&#40;</span> <span class="st0">&#8216;mime_type_lib.php&#8217;</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re0">$data</span> = get_file_mime_type<span class="br0">&#40;</span> <span class="st0">&#8216;/home/user/public_html/image.jpg&#8217;</span>, <span class="kw2">true</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li2">
<div class="de2">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&quot;MIME Type: ${data['mime_type']}<span class="es0">\n</span>&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <a href="http://www.php.net/echo"><span class="kw3">echo</span></a> <span class="st0">&quot;Method: ${data['method']}<span class="es0">\n</span>&quot;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">?&gt;</span></div>
</li>
</ol>
</div>
<p>This produces the following output:</p>
<div class="code">MIME Type: image/jpeg<br />
Method: from_array</div>
<p>The possible methods are: fileinfo, <code>mime_content_type</code>, from_array, and last_resort. The first two should be self-explanitory. from_array means that the resulting MIME type was pulled from the array built into the function. last_resort means that the type could not be identified which results in a generic MIME type of &#8220;application/octet-stream&#8221; being used.</p>
<h3>Conclusion</h3>
<p>Frankly, I&#8217;m disappointed in the solutions provided by PHP to detect MIME types. I have access to a very stable, highly-regarded shared host and an extremely powerful, up-to-date dedicated host, neither of which have the ability to use either of the PHP solutions to detect MIME types without adding additional software.</p>
<p>I don&#8217;t remember which version of PHP my dedicated box started with, but I did upgrade to 5.1.6 using the standard repository back in October. I was only able to update to 5.2.6 by using the <a href="http://www.jasonlitka.com/yum-repository/" target="_blank">Utter Ramblings repository</a> by <a href="http://www.jasonlitka.com/" target="_blank">Jason Litka</a>. True, I could compile and install 5.3 or the PECL package myself, but I produce software for people who don&#8217;t have a clue what a compiler is, let alone what repositories or PECL extensions are.</p>
<p>It&#8217;s things like this that make development a pain. I could always just be a jerk of a developer, have the line &#8220;requires PHP 5.3+&#8221;, and tell all people that can&#8217;t run the software to check the requirements. However, I think that my job is to make the end-user&#8217;s life easier, not more complicated.</p>
<p>Hopefully others that have had woes dealing with this situation can make use of my code, and we can all just wait a few years until the majority of hosts have a PHP version that supports these calls natively.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/02/14/generating-mime-type-in-php-is-not-magic/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>W2k9? AKA: The Planet is Down?</title>
		<link>http://chrisjean.com/2009/01/02/w2k9-aka-the-planet-is-down/</link>
		<comments>http://chrisjean.com/2009/01/02/w2k9-aka-the-planet-is-down/#comments</comments>
		<pubDate>Fri, 02 Jan 2009 21:36:57 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Random Ramblings]]></category>
		<category><![CDATA[Hostgator]]></category>
		<category><![CDATA[Layered Tech]]></category>
		<category><![CDATA[network outage]]></category>
		<category><![CDATA[Pingdom]]></category>
		<category><![CDATA[Rackspace]]></category>
		<category><![CDATA[The Planet]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=450</guid>
		<description><![CDATA[It looks like there is a big networking problem over at The Planet. Hostgator, which hosts this blog and is hosted by The Planet, is suffering terribly from this problem. My uptime with Hostgator is so high, that Pingdom tracks my site at 100% uptime since it doesn&#8217;t track beyond 99.99% uptime. So, this has [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>It looks like there is a big networking problem over at <a href="http://www.theplanet.com/" target="_blank">The Planet</a>. <a href="http://hostgator.com/" target="_blank">Hostgator</a>, which hosts this blog and is hosted by The Planet, is suffering terribly from this problem. My uptime with Hostgator is so high, that <a href="http://pingdom.com/" target="_blank">Pingdom</a> tracks my site at 100% uptime since it doesn&#8217;t track beyond 99.99% uptime. So, this has to be causing lots of stress for the engineers at both companies.</p>
<p>I first noticed this problem when working on a site that is hosted at Hostgator. The site completely failed to load and pings failed 50% of the time.</p>
<p><span id="more-450"></span></p>
<p>From what I can tell one of the primary switches that handles large loads for The Planet either failed, froze up, or is under extremely high of traffic loads. At first, my site wasn&#8217;t effected, but it seems like they are quickly shunting traffic away from the troubled switch, which is causing the other switches to be under greater stress. This has allowed some of the failed sites to respond after abnormally-long load times, but also has the side effect of causing the previously unaffected sites, such as mine, to degrade in performance as well.</p>
<p>I have been incredibly impressed with The Planet through my years of experience with their dedicated systems. Similarly, I have had nothing but the best experiences with Hostgator, which is why I still host my blog on their system despite having a personal dedicated server.</p>
<p>Best of luck to the network engineers as they get this problem sorted, and welcome to 2009. <img src='http://chrisjean.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Update</h2>
<p>It looks like the problem is much bigger than I originally believed. It&#8217;s possible that a regional switch around the Dallas/Fort Worth area went down. So far, I&#8217;ve found that <a href="http://layeredtech.com/" target="_blank">Layered Tech</a>, The Planet, <a href="http://rackspace.com/" target="_blank">Rackspace,</a> and most of the sites that I know are hosted in that region are either completely inaccessible or extremely slow to respond.</p>
<p>The problem seems to be getting better curently with many of the previously inaccessible sites now coming back up. Hopefully the problem has been resolved.</p>
<h2>Update #2</h2>
<p>I contacted The Planet, and the guy gave me two responses to my questions about the outage: &#8220;no&#8221; and &#8220;ok&#8221;. Not exactly helpful. I then tried to have a live chat with Layered Tech (who I have had great hosting experience with, so this isn&#8217;t knocking their service), but I just ended up sending off an email apparently. I contacted Rackspace (another great host who gets my recommendation), and I got a very helpful person who didn&#8217;t have any information on the outage but quickly started engaging me in a sales discussion (Tomas S, you sure do a good job with keeping on the sales talk). I then contacted Hostgator via live chat and was immediately given information that a cable provider was having large-scale outages that mostly centered around southern California but also was causing problems for the DFW area. The support person also indicated that the cable provider was slow to provide details and updates.</p>
<p>So, amazingly, the small fish out of all the companies I contacted not only had the fastest response but also was on the ball in terms of having and providing information about an issue that affects me.</p>
<p>Thinking back on each of the live chats offered, Hostgator was the only one that actually seemed to use the Live Chat for more than just sales. Once again, Hostgator proves that they truly do have great service and support.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/01/02/w2k9-aka-the-planet-is-down/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

