<?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; PHP</title>
	<atom:link href="http://chrisjean.com/tag/php/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>Creating a PHP ICO Creator for Favicons</title>
		<link>http://chrisjean.com/2011/07/21/creating-a-php-ico-creator-for-favicons/</link>
		<comments>http://chrisjean.com/2011/07/21/creating-a-php-ico-creator-for-favicons/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 15:15:58 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[favicon]]></category>
		<category><![CDATA[ICO]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://chrisjean.com/?p=1965</guid>
		<description><![CDATA[For the past couple of weeks, I have worked on creating a PHP library to create ICO files. This has been difficult as all the documentation for the ICO format is either sparse or not completely documented. I&#8217;m doing this since I have yet to find a way of creating a valid favicon file using [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>For the past couple of weeks, I have worked on creating a PHP library to create ICO files. This has been difficult as all the documentation for the ICO format is either sparse or not completely documented.</p>
<p>I&#8217;m doing this since I have yet to find a way of creating a valid favicon file using just PHP and PHP&#8217;s GD library. Sure, I can create a PNG file and change the extension to &#8220;.ico&#8221;, but that doesn&#8217;t work in all browsers, on all operating systems (such as Windows XP), and is more of a hack than a valid method for creating favicon files.</p>
<p>So, it is time to make one. I have a placeholder github repository named <a title="GitHub Repository - PHP ICO" href="https://github.com/chrisbliss18/php-ico">php-ico</a>.</p>
<p>The primary goal is to make a robust, reliable library that creates valid ICO files that can be properly rendered on Windows XP+ and all the major browsers. Thus, my initial goal is not to support every format that exists nor is it to support parsing the ICO files. If the project gets enough attention, I&#8217;ll look at expanding the scope.</p>
<p>Here are the resources that I&#8217;ve found helpful as I&#8217;ve worked on this project:</p>
<ul>
<li><a title="Wikipedia - ICO (File Format)" href="http://en.wikipedia.org/wiki/ICO_%28file_format%29">ICO (file format)</a> &#8211; Wikipedia article about the ICO file format. This has a very comprehensive description of the ICO header. It is sparse on details about the format of the image data.</li>
<li><a title="Wikipedia - BMP file format" href="http://en.wikipedia.org/wiki/BMP_file_format">BMP file format</a> &#8211; Wikipedia article about the BMP file format. This helped me understand the headers and pixel data format for the BMP image data.</li>
<li><a title="Wikipedia - Portable Network Graphics" href="http://en.wikipedia.org/wiki/Portable_Network_Graphics">Portable Network Graphics</a> &#8211; Wikipedia article about the PNG file format. This gave me what I needed to know to identify PNG image data.</li>
<li><a title="Article - Windows Bitmap File Format" href="http://www.mediatel.lu/workshop/graphic/2D_fileformat/h_bmp.html">Windows Bitmap File Format</a> &#8211; Very good article that delves into more details about the BMP file format. The extra details about the different types of headers, compression methods, compression encoding, and examples were very helpful.</li>
<li><a title="Microsoft Developer Network Article - Icons" href="http://msdn.microsoft.com/en-us/library/ms997538.aspx">Icons</a> &#8211; A Microsoft Developer Network article from 1995 that provides the original ICO file format spec. While this is the most authoritative, I really didn&#8217;t find this to be as much help as other sources.</li>
<li><a title="The Code Project Article - Replacing ICON resources in EXE and DLL files" href="http://www.codeproject.com/KB/DLL/ICON_Resources.aspx?display=Mobile">Replacing ICON resources in EXE and DLL files</a> &#8211; Article from The Code Project that has a breakdown of the format similar to what is found in the MSDN article. Example C code is provided.</li>
<li><a title="Bugzilla@Mozilla - Bug 600556 - Support Vista-style ICO files" href="https://bugzilla.mozilla.org/show_bug.cgi?id=600556">Support Vista-style ICO files</a> &#8211; Mozilla Bugzilla filed bug. The discussion has some great information about methods used to reliably parse varying ICO formats and structures. It also has some good test ICO files to try.</li>
<li><a title="Chironex Software Post - Convert HBITMAP to .ICO file" href="http://chironexsoftware.com/blog/?p=13">Convert HBITMAP to .ICO file</a> &#8211; This Chironex Software blog post provided the last piece I needed: how to structure the opacity mask data. Where he found this information (since I didn&#8217;t find it in any of the above articles) I haven&#8217;t a clue.</li>
</ul>
<p>If this post gets some traction and interest, I&#8217;ll consider putting together a post detailing all the different pieces I&#8217;ve found here. I&#8217;m not a spec writer, but I&#8217;d try my best. Let me know if you&#8217;d like to have me work on this.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2011/07/21/creating-a-php-ico-creator-for-favicons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fix PHP 4 &#8220;Client does not support authentication protocol requested by server&#8221;</title>
		<link>http://chrisjean.com/2010/05/25/fix-php-4-client-does-not-support-authentication-protocol/</link>
		<comments>http://chrisjean.com/2010/05/25/fix-php-4-client-does-not-support-authentication-protocol/#comments</comments>
		<pubDate>Tue, 25 May 2010 20:25:44 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1774</guid>
		<description><![CDATA[I&#8217;m working on building an ideal server setup that allows for both PHP 4 and PHP 5 on Apache with suPHP (I&#8217;ll blog about this later). While testing my PHP 4 build, I got the following error: Warning: mysql_connect() [function.mysql-connect]: Client does not support authentication protocol requested by server; consider upgrading MySQL client in /var/www/test-php.php [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>I&#8217;m working on building an ideal server setup that allows for both <a href="http://php.net/">PHP</a> 4 and PHP 5 on <a href="http://www.apache.org/">Apache</a> with <a href="http://www.suphp.org/Home.html">suPHP</a> (I&#8217;ll blog about this later). While testing my PHP 4 build, I got the following error:</p>
<p style="padding-left: 30px;">Warning: mysql_connect() [function.mysql-connect]: Client does not support authentication protocol requested by server; consider upgrading MySQL client in /var/www/test-php.php  on line 3<br />
Couldn&#8217;t authenticate with MySQL</p>
<p>The code I used to test this is quite simple:</p>
<pre>&lt;?php

if ( false === ( $db = mysql_connect( 'localhost', 'username', 'password' ) ) )
    die( "Couldn't authenticate with MySQL" );

if ( false === mysql_select_db( 'database' ) )
    die( "Couldn't connect to database" );

echo "Yay!";

?&gt;</pre>
<p>After digging around for a bit, I found that mixing PHP 4 with a MySQL version greater than or equal to 4.1 causes this problem. MySQL 4.1 introduced a new password caching scheme that PHP 4 can&#8217;t work with.</p>
<p>The solution is to update the database user&#8217;s password using the OLD_PASSWORD function of MySQL. For example:</p>
<pre class="terminal"><span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@office</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">mysql -u root -p mysql</span>
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 267
Server version: 5.1.41-3ubuntu12.1 (Ubuntu)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

<span style="color:#8FED99;">mysql&gt;</span> <span style="color:#FFF;">update user set Password=OLD_PASSWORD('<span style="text-decoration: underline;">password</span>') WHERE User='<span style="text-decoration: underline;">username</span>';</span>
Query OK, 0 rows affected (0.02 sec)
Rows matched: 0  Changed: 0  Warnings: 0

<span style="color:#8FED99;">mysql&gt;</span> <span style="color:#FFF;">flush privileges;</span>
Query OK, 0 rows affected (0.00 sec)

<span style="color:#8FED99;">mysql&gt;</span></pre>
<p>Note the underlined areas. That is where you&#8217;ll want to provide your own username and password.</p>
<p>Once you&#8217;ve followed these steps, both PHP 4 and PHP 5 will be able to communite with the database.</p>
<p>Thanks to <a href="http://www.digitalpeer.com/id/mysql">digitalpeer</a> for providing the answer to my issue.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2010/05/25/fix-php-4-client-does-not-support-authentication-protocol/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Use PHP Pear with Ubuntu</title>
		<link>http://chrisjean.com/2009/11/02/use-php-pear-with-ubuntu/</link>
		<comments>http://chrisjean.com/2009/11/02/use-php-pear-with-ubuntu/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 21:16:48 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[Karmic Kaola]]></category>
		<category><![CDATA[PEAR]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=1700</guid>
		<description><![CDATA[PEAR is PHP&#8217;s equivalent of Perl&#8217;s CPAN. It offers hundreds of ready-to-use code modules that can make projects go much more quickly than having to hand code everything. However, it never seems like PEAR is easy to get running. Installing the Needed Software In Ubuntu, installing the following packages will quickly get you started with [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p><a href="http://pear.php.net/" target="_blank">PEAR</a> is PHP&#8217;s equivalent of <a href="http://cpan.org/" target="_blank">Perl&#8217;s CPAN</a>. It offers hundreds of ready-to-use code modules that can make projects go much more quickly than having to hand code everything. However, it never seems like PEAR is easy to get running.</p>
<h3>Installing the Needed Software</h3>
<p>In Ubuntu, installing the following packages will quickly get you started with PEAR: php5-cli, php5-dev, and php-pear.</p>
<p>Make sure that you read the next section about problems with using PEAR to install PEAR packages if you are running 9.10, Karmic Kaola.</p>
<p>Here&#8217;s an example of how to quickly install those packages from the terminal.</p>
<pre class="terminal"><span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@rommie</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo apt-get install php5-cli php5-dev php-pear</span>
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
autoconf autoconf2.13 automake automake1.4 autotools-dev libltdl-dev libssl-dev libtool m4 php5-common shtool zlib1g-dev
Suggested packages:
autobook autoconf-archive gnu-standards autoconf-doc gettext libtool-doc automaken gfortran fortran95-compiler gcj php5-suhosin
The following NEW packages will be installed:
autoconf autoconf2.13 automake automake1.4 autotools-dev libltdl-dev libssl-dev libtool m4 php-pear php5-cli php5-common php5-dev shtool zlib1g-dev
0 upgraded, 15 newly installed, 0 to remove and 5 not upgraded.
Need to get 0B/8,690kB of archives.
After this operation, 27.7MB of additional disk space will be used.
Do you want to continue [Y/n]? y
Selecting previously deselected package m4.
(Reading database ... 127272 files and directories currently installed.)
Unpacking m4 (from .../archives/m4_1.4.13-2_i386.deb) ...
...</pre>
<p>With these packages, you are ready to roll with PHP and PEAR in Ubuntu.</p>
<h3>Problem with Ubuntu 9.10 Karmic Kaola</h3>
<p>A great thing about PEAR is that you can quickly install packages with a simple command. For example, &#8220;sudo pear install PHP_Parser-0.2.1&#8243; will install the <a href="http://pear.php.net/package/PHP_Parser/" target="_blank">PHP_Parser</a> package. However, this doesn&#8217;t work properly in Ubuntu 9.10, Karmic Kaola.</p>
<p>Output of the standard PEAR install command can be seen below:</p>
<pre class="terminal"><span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@rommie</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo pear install PHP_Parser-0.2.1</span>
downloading PHP_Parser-0.2.1.tgz ...
Starting to download PHP_Parser-0.2.1.tgz (70,782 bytes)
.................done: 70,782 bytes</pre>
<p>While this doesn&#8217;t look wrong, it has actually failed. Rather than installing the package, it has simply downloaded the archive, encountered an unchecked error, and crashed. A successful installation has a message saying that the installation is successful.</p>
<p>This problem can be easily fixed by giving the install command the &#8220;-Z&#8221; option. For example:</p>
<pre class="terminal"><span style="color:#8FED99;">[<span style="color:#BBFF33;">chris@rommie</span> <span style="color:#729FCF;">~</span>]$</span> <span style="color:#FFF;">sudo pear install -Z PHP_Parser-0.2.1</span>
downloading PHP_Parser-0.2.1.tar ...
Starting to download PHP_Parser-0.2.1.tar (Unknown size)
.............................................................................done: 533,504 bytes
install ok: channel://pear.php.net/PHP_Parser-0.2.1</pre>
<p>Notice the &#8220;install ok: &#8230;&#8221; portion of the message. That&#8217;s what you should see at the end of a successful installation.</p>
<p>For more details on this bug, please check out <a href="https://bugs.launchpad.net/ubuntu/+source/php5/+bug/451314" target="_blank">Bug #451314</a> on the Ubuntu bug tracker.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/11/02/use-php-pear-with-ubuntu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>Unicode Support on CentOS 5.2 with PHP and PCRE</title>
		<link>http://chrisjean.com/2009/01/31/unicode-support-on-centos-52-with-php-and-pcre/</link>
		<comments>http://chrisjean.com/2009/01/31/unicode-support-on-centos-52-with-php-and-pcre/#comments</comments>
		<pubDate>Sat, 31 Jan 2009 06:00:32 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[PCRE]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[regular expressions]]></category>
		<category><![CDATA[Unicode]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=820</guid>
		<description><![CDATA[Yesterday, I talked about how to get the most out of running regular expressions in PHP. The reason that I needed to dig in deep on regular expression syntax with PHP is because I needed to write some regular expressions that deal with Unicode characters. After much reading, I believed that I knew everything that [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p><a href="http://chrisjean.com/2009/01/30/php-regular-expression-syntax-references/" target="_blank">Yesterday</a>, I talked about how to get the most out of running regular expressions in PHP. The reason that I needed to dig in deep on regular expression syntax with PHP is because I needed to write some regular expressions that deal with Unicode characters.</p>
<p>After much reading, I believed that I knew everything that I needed. I started writing some regex strings and testing the code. Unfortunately, every time I ran a test with a string that contained Unicode characters, the match failed. When I removed the Unicode characters from the string and tested again, it would work. I was baffled.</p>
<p><span id="more-820"></span></p>
<h3>Finding the Problem</h3>
<p>I had the regex testing characters (&#8216;\X&#8217;, &#8216;\pL&#8217;, etc) inside of a character class, such as &#8216;[\X-]&#8216;, since I was creating a regex to test for domains. I wrote a really simple rule by simply looking for &#8216;/^\X$/&#8217; and testing the regex with a single Unicode character. Amazingly, having the &#8216;\X&#8217; outside of the square brackets changed everything as I now received the following very concerning warning:</p>
<div class="code">PHP Warning:  preg_match(): Compilation failed: support for \P, \p, and \X has not been compiled at offset 2 in wp-content/plugins/dnsyogi/testunicode.php on line 4</div>
<p>Since PHP uses the PCRE engine to run regular expressions, I started to dig into it. I found out that I could query PCRE directly. I ended up with something very similar:</p>
<div class="code">$ pcregrep &#8216;/\X*/u&#8217; character.txt<br />
pcregrep: Error in command-line regex at offset 2: support for \P, \p, and \X has not been compiled</div>
<p>It looked like the error was coming from PCRE itself. I searched around for a while thinking that I could simply install a new package using yum. I hoped to find something like pcre-utf8, pcre-unicode, php-pcre-unicode, or something to make it simple and quick to add this support since I much prefer using package management tools rather than compiling and installing from source.</p>
<p>Unfortunately, no such package exists. This support is something that must be an option that PCRE is compiled with, and my CentOS repository only has packages that don&#8217;t include that support. After much digging around, I found that this isn&#8217;t necessarily CentOS&#8217;s fault as this package has carried over from the RHEL (Red Hat Enterprice Linux) side of things.</p>
<p>A great way of checking to see if this is an issue on your system is by running the following:</p>
<pre style="padding-left: 30px;">$ pcretest -C
PCRE version 6.6 06-Feb-2006
Compiled with
  UTF-8 support
  No Unicode properties support
  Newline character is LF
  Internal link size = 2
  POSIX malloc threshold = 10
  Default match limit = 10000000
  Default recursion depth limit = 10000000
  Match recursion uses stack</pre>
<p>This is the output that I received. Notice the &#8220;UTF-8 support&#8221; and the &#8220;No Unicode properties support&#8221; lines. This means that PRCE was compiled with the &#8220;&#8211;enable-utf8&#8243; configure option which allows PCRE to recognize and work with UTF-8 encoded strings. However, it wasn&#8217;t compiled with the &#8220;&#8211;enable-unicode-properties&#8221; configure option which works in conjunction with the enable-utf8 option to add support for the &#8216;\p&#8217;, &#8216;\P&#8217;, and &#8216;\X&#8217; character classes.</p>
<p>This seems to have been an oversight when the rpm file was first put together. Fortunately, there is a way to fix it.</p>
<h3>Fixing the Problem</h3>
<p>Since I&#8217;m sure that many of you are like me and would rather not manually compile and install software outside of the package management system, the solution is to update the rpm to have the option that it needs and install it.</p>
<p>I had never done this before. Fortunately, I found a very helpful guide that details this process out very nicely: <a href="http://bradthemad.org/tech/notes/patching_rpms.php" target="_blank">How to patch and rebuild an RPM package</a>.</p>
<p>I have provided the new rpm file that I have built at the bottom of this post. If you don&#8217;t care about all this jibber-jabber, you can skip down there and grab the file. However, if you would like to learn how to address this issue yourself or have a system that my file will not support, please read on to see how I rebuilt the rpm with the new option.</p>
<h3>Rebuilding the rpm</h3>
<ol>
<li>The first thing I did is set up my ~/.rpmmacros file and src/rpm folder structure as detailed in the Setup section of <a href="http://bradthemad.org/tech/notes/patching_rpms.php" target="_blank">the guide</a> that I&#8217;m following. I&#8217;ll simply refer you over there as it doesn&#8217;t need repeating here.</li>
<li>I needed to grab the source rpm for the current version of PCRE on my platform. I&#8217;m on CentOS 5.2 with version 6.6 of PCRE. I found the matching source rpm file (pcre-6.6-2.el5_1.7.src.rpm) <a href="http://mirrors.kernel.org/centos/5.2/os/SRPMS/pcre-6.6-2.el5_1.7.src.rpm" target="_blank">here</a>.</li>
<li>I then installed the source rpm in order to gain access to its files:
<pre style="padding-left: 30px;">$ rpm -ivh pcre-6.6-2.el5_1.7.src.rpm</pre>
<p>This put the necessary files into my ~/src/rpm/SOURCES and ~/src/rpm/SPECS folders.</li>
<li>I opened up the ~/src/rpm/SPECS/pcre.spec file and found the following line:
<pre style="padding-left: 30px;">%configure --enable-utf8</pre>
<p>I changed it to include the Unicode properties option:</p>
<pre style="padding-left: 30px;">%configure --enable-utf8 --enable-unicode-properties</pre>
<p>I then saved and closed the file.</li>
<li>This is the only change that I needed to make. So, now it is time to build the new rpm file. I simply ran the following to build it:
<pre style="padding-left: 30px;">$ rpmbuild -ba ~/src/rpm/SPECS/pcre.spec</pre>
<p>Toward the end of the large amount of output, I received the following:</p>
<pre style="padding-left: 30px;">Wrote: ~/src/rpm/SRPMS/pcre-6.6-2.7.src.rpm
Wrote: ~/src/rpm/RPMS/x86_64/pcre-6.6-2.7.x86_64.rpm
Wrote: ~/src/rpm/RPMS/x86_64/pcre-devel-6.6-2.7.x86_64.rpm
Wrote: ~/src/rpm/RPMS/x86_64/pcre-debuginfo-6.6-2.7.x86_64.rpm</pre>
<p>This tells me exactly where I can find my new source rpm and rpm files.</li>
</ol>
<h3>Updated rpm File for CentOS 5.2 64-bit</h3>
<p>If you are running a 64-bit version of CentOS 5.2, the following file should work for you. If you have a different architecture, Linux distro, or encounter any errors when trying to install this file, then you should follow the instructions above to build an rpm that is suitable for your distribution.</p>
<p><a href="http://chrisjean.com/wp-content/uploads/2009/01/pcre-66-27x86_64.rpm" target="_blank">pcre-6.6-2.7.x86_64.rpm</a> &#8211; PCRE 6.6 for CentOS 5.2 64-bit</p>
<div class="post-notice" style="margin-bottom:10px;">Thanks <a href="http://chrisjean.com/2009/01/31/unicode-support-on-centos-52-with-php-and-pcre/comment-page-1/#comment-1144">Robin</a> for providing a 32-bit version: <a href="http://chrisjean.com/wp-content/uploads/2009/01/pcre-6.6-2.7.i386.rpm">pcre-6.6-2.7.i386.rpm</a></div>
<h3>Installing New rpm</h3>
<p>Now that I have my new rpm file, I just need to install it. Since I already have a pcre package installed, I need to tell the rpm command to update rather than install. The following command does this for me:</p>
<pre style="padding-left: 30px;"># rpm -Uvh ~/src/rpm/RPMS/x86_64/pcre-6.6-2.7.x86_64.rpm</pre>
<p>Notice that I need to be root to run this command.</p>
<p>Finally, to verify that everything worked, I ran the pcrecheck program again:</p>
<pre style="padding-left: 30px;">$ pcretest -C
PCRE version 6.6 06-Feb-2006
Compiled with
  UTF-8 support
  Unicode properties support
  Newline character is LF
  Internal link size = 2
  POSIX malloc threshold = 10
  Default match limit = 10000000
  Default recursion depth limit = 10000000
  Match recursion uses stack</pre>
<p>Looks good.</p>
<p>Finally, time to move on with life.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/01/31/unicode-support-on-centos-52-with-php-and-pcre/feed/</wfw:commentRss>
		<slash:comments>63</slash:comments>
		</item>
		<item>
		<title>PHP Regular Expression Syntax References</title>
		<link>http://chrisjean.com/2009/01/30/php-regular-expression-syntax-references/</link>
		<comments>http://chrisjean.com/2009/01/30/php-regular-expression-syntax-references/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 16:47:09 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=812</guid>
		<description><![CDATA[Since beginning work on my DNS Yogi site, I&#8217;ve had to do numerous regular expressions to matching all sorts of string bits. I quickly ran into problems when I realized that I need to add support for Unicode characters since certain TLD registrars support registrations with non-Latin characters. The main issue is that there are [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>Since beginning work on my <a href="http://dnsyogi.com/">DNS Yogi</a> site, I&#8217;ve had to do numerous <a href="http://en.wikipedia.org/wiki/Regular_expression" target="_blank">regular expressions</a> to matching all sorts of string bits. I quickly ran into problems when I realized that I need to add support for <a href="http://en.wikipedia.org/wiki/Unicode" target="_blank">Unicode</a> characters since certain <a href="http://en.wikipedia.org/wiki/Top-level_domain" target="_blank">TLD</a> registrars support registrations with non-Latin characters.</p>
<p>The main issue is that there are multiple regular expression engines. <a href="http://php.net/" target="_blank">PHP</a> uses a flavor of the <a href="http://www.pcre.org/" target="_blank">PCRE</a> (Perl Compatible Regular Expression) engine. Each engine and varient of an engine has a slightly different way of handling regular expression syntax. I needed to find out exactly how the PHP regular expression engine worked, and finding that information was not easy.</p>
<p><span id="more-812"></span></p>
<p>I&#8217;d have to say that there isn&#8217;t a single resource that will provide everything needed, and I certainly don&#8217;t believe that I can produce and maintain a better one. So, this post will act as a compilation of resources that together provide a robust overview of how PHP handles regular expressions.</p>
<ul>
<li>Your first stop should be the <a href="http://www.php.net/manual/" target="_blank">PHP Manual</a>&#8216;s page on the <a href="http://www.php.net/manual/en/function.preg-match.php" target="_blank">preg_match</a> function. This page will get you started on how to run regular expressions using PHP. In addition, you should look at the <a href="http://www.php.net/manual/en/function.preg-match-all.php" target="_blank">preg_match_all</a>, <a href="http://www.php.net/manual/en/function.preg-replace.php" target="_blank">preg_replace</a>, and <a href="http://www.php.net/manual/en/function.preg-split.php" target="_blank">preg_split</a> function references so you get a good overview of what each function can do.</li>
<li>Next, stop by <a href="http://www.regular-expressions.info/" target="_blank">Regular-Expressions.info</a> and read through their page on <a href="http://www.regular-expressions.info/php.html" target="_blank">PHP</a> to get an outsider view of how PHP handles regular expressions. If you aren&#8217;t familiar with regular expressions, you will gain an amazing amount of knowledge about how to build and use them by reading through their <a href="http://www.regular-expressions.info/tutorialcnt.html" target="_blank">Regex Tutorial</a>.</li>
<li>Now it&#8217;s time to really dig in and get dirty on the internals of the PCRE engine that PHP uses. The <a href="http://www.regextester.com/pregsyntax.html" target="_blank">PCRE Regular Expression Pattern Syntax Reference (PHP preg*)</a> document is an extremely in-depth reference that details the finer points of how the regular expression engine in PHP really works. If you want to know how to build advanced regex patterns in PHP, this is the document for you.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/01/30/php-regular-expression-syntax-references/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install FFmpeg and ffmpeg-php on CentOS Easily</title>
		<link>http://chrisjean.com/2009/01/13/install-ffmpeg-and-ffmpeg-php-on-centos-easily/</link>
		<comments>http://chrisjean.com/2009/01/13/install-ffmpeg-and-ffmpeg-php-on-centos-easily/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 23:59:13 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[DAG]]></category>
		<category><![CDATA[FFmpeg]]></category>
		<category><![CDATA[ffmpeg-php]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[yum]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=575</guid>
		<description><![CDATA[FFmpeg is an amazing collection of open-source tools that can record and stream video and audio. However, it can also transcode video and audio (convert the files to different formats), and that is what has me so excited. There&#8217;s also a great PHP package called ffmpeg-php that allows for easy use of FFmpeg from inside [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p><a href="http://ffmpeg.mplayerhq.hu/" target="_blank">FFmpeg</a> is an amazing collection of open-source tools that can record and stream video and audio. However, it can also transcode video and audio (convert the files to different formats), and that is what has me so excited. There&#8217;s also a great <a href="http://php.net/" target="_blank">PHP</a> package called <a href="http://ffmpeg-php.sourceforge.net/" target="_blank">ffmpeg-php</a> that allows for easy use of FFmpeg from inside PHP scripts. Today, I&#8217;m going to see if I can&#8217;t help you get both of these set up on your system.</p>
<p>Admittedly, it&#8217;s been a while since I&#8217;ve tried to install FFmpeg, about two years. I recently thought up some ideas on how I&#8217;d like to use FFmpeg, so I thought it was time to give it a try yet again. Today, I&#8217;m proud to say that installing FFmpeg is so much easier to install compared to the past, that I dare say it&#8217;s simple.</p>
<p>Here is my experience with installing FFmpeg on my server and how to fix the pitfalls that I encountered.</p>
<p><span id="more-575"></span></p>
<h3>Preface</h3>
<p>Note that I did all the following steps on a <a href="http://www.centos.org/" target="_blank">CentOS</a> server. The specific version is CentOS x64 5.2.</p>
<p>These instructions can work for other distros with little or no modifications, but some distros will be completely different. For example, the <a href="http://dag.wieers.com/rpm/" target="_blank">DAG RPM Repository</a> that I&#8217;m using (more info below) has support for the following distros: <a href="http://www.redhat.com/" target="_blank">Red Hat Enterprise Linux</a>, <a href="http://fedoraproject.org/" target="_blank">Fedora Core</a>, <a href="http://us.fixstars.com/products/ydl/" target="_blank">Yellow Dog Linux</a>, <a href="http://auroralinux.org/" target="_blank">Aurora Linux</a>, <a href="http://www.centos.org/" target="_blank">CentOS</a>, <a href="https://www.scientificlinux.org/" target="_blank">Scientific Linux</a> (they really need to get a verified SSL cert), <a href="http://www.taolinux.org/" target="_blank">TaoLinux</a>, <a href="http://whiteboxlinux.org/" target="_blank">WhiteBox Linux</a>, <a href="http://www.lineox.net/" target="_blank">Lineox</a>, and <a href="http://www.blagblagblag.org/" target="_blank">BLAG</a>. Other distros will need to use a different repository.</p>
<p>If you successfully get FFmpeg running on another distro, please comment your changes here and I&#8217;ll update the post (and make sure you get credit of course).</p>
<p>Also note that I experienced some bumps in the road while installing everything. While many of you may not experience these issues, I found it important to document these problems and how I fixed them in case you encounter them.</p>
<h3>Preparing</h3>
<p>The first thing that you need to do is set up the <a href="http://dag.wieers.com/rpm/" target="_blank">DAG repository</a>. This repository is an actively-maintained repository that provides a staggering number of packages with current or near current builds. Adding this repository is a great way to run the latest offerings of many packages.</p>
<p>Adding the DAG repository is simple. I&#8217;m using <a href="http://fedoraproject.org/wiki/Tools/yum" target="_blank">yum</a>, so I did the following to add the repository:</p>
<ol>
<li>Create and open a new file called <strong>/etc/yum.repos.d/dag.repo</strong>. I ran &#8220;<strong><code>vi /etc/yum.repos.d/dag.repo</code></strong>&#8220;.</li>
<li>Add the following text to the file:
<div style="padding-left: 20px;"><code>[dag]<br />
name=DAG RPM Repository<br />
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag<br />
gpgcheck=1<br />
enabled=1</code></div>
</li>
<li>Finally, save and close the file.</li>
</ol>
<p>In order to successfully use the DAG repository with tools such as yum, you need to add <a href="http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt" target="_blank">DAG&#8217;s GPG key</a>. Failure to do so will result in an error like the following:</p>
<div style="padding-left: 20px;"><code>warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 6b8d79e6<br />
Public key for faac.x86_64.1.26-1.el5.rf.rpm is not installed</code></div>
<p>In order to add the GPG key for DAG, run the following:</p>
<div style="padding-left: 20px;"><code>rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt</code></div>
<p>The <a href="http://dag.wieers.com/rpm/FAQ.php#B1" target="_blank">DAG: Frequently Asked Questions</a> page has additional instructions on how to get the repository loaded and working on your distro.</p>
<p>Now that DAG is setup, it&#8217;s a good idea to update all your packages.</p>
<div style="padding-left: 20px;"><code>yum update</code></div>
<p>Depending on the packages you currently have installed, this could potentially upgrade, install, or replace numerous packages that may or may not be very important to you. Make sure you carefully look through that list and do any necessary preparations before telling yum that it can go ahead.</p>
<p>For example, yum told me that it was going to replace my current <a href="http://dev.mysql.com/" target="_blank">MySQL</a> interface library for <a href="http://www.perl.org/" target="_blank">Perl</a> with a new one. I added to my check list a note to verify that my Perl code functioned correctly after the install.</p>
<p>I ran into another hitch when I told yum to go ahead with the update. It informed me that my current version of <a href="http://subversion.tigris.org/" target="_blank">Subversion</a> conflicted with the new version it wanted to install. When this happens, you need to remove the old package before proceeding. This time, I made backups of all of my repositories and my <strong>/etc/sysconfig/svnserve</strong> file before proceeding just in case. I then removed Subversion &#8220;<strong><code>yum remove subversion</code></strong>&#8220;, ran the update process &#8220;<strong><code>yum update</code></strong>&#8220;, and installed Subversion again &#8220;<strong><code>yum install subversion</code></strong>&#8220;.</p>
<h3>Installing &#8211; FFmpeg</h3>
<p>Now you are ready to install FFmpeg with yum. I wanted to install all the available FFmpeg packages, so I first asked yum what was available.</p>
<div style="padding-left: 20px;"><code>yum search ffmpeg</code></div>
<p>Searching through the results, I found that three packages need to be installed: ffmpeg, ffmpeg-devel, and ffmpeg-libpostproc.</p>
<div style="padding-left: 20px;"><code>yum install ffmpeg ffmpeg-devel ffmpeg-libpostproc</code></div>
<p><em>Note: If you install ffmpeg-libpostproc, the entire FFmpeg software library changes from the LGPL license to the GPL license.</em></p>
<p>After a couple of minutes, the packages and the packages that they depend on were installed.</p>
<p>I simply ran &#8220;<strong><code>ffmpeg</code></strong>&#8221; from the command line, and I took the lack of threatening error or warning messages as a good sign that things were working.</p>
<h3>Preparing for ffmpeg-php</h3>
<p>I often work with programs through command line calls in code, but I wanted something more robust this time, so I looked around and found <a href="http://ffmpeg-php.sourceforge.net/" target="_blank">ffmpeg-php</a>. Based on the <a href="http://ffmpeg-php.sourceforge.net/doc/api/" target="_blank">API</a>, it looks to be a great tool to interface PHP and FFmpeg.</p>
<p>There are four things that are required to successfully install and run ffmpeg-php; they are:</p>
<ul>
<li>ffmpeg-0.4.9_pre1 or higher</li>
<li>php-4.3.0 or higher</li>
<li>gd-2.0 or higher</li>
<li>php-devel</li>
</ul>
<p>PHP and FFmpeg should be good to go since at the time of this writing, DAG has PHP version 5.1.6 and FFmpeg version 0.4.9. <a href="http://www.boutell.com/gd/" target="_blank">GD</a> and php-devel can be easily installed by running the following yum command:</p>
<div style="padding-left: 20px;"><code>yum install php-gd php-devel</code></div>
<p>In case you are wondering what php-devel is for, it installs the <a href="http://php.mirrors.ilisys.com.au/manual/en/install.pecl.phpize.php" target="_blank">phpize</a> program which is used to install ffmpeg-php.</p>
<h3>Installing ffmpeg-php</h3>
<p>Now we are ready to install ffmpeg-php. This can be done in six easy steps:</p>
<ol>
<li>Download the <a href="http://sourceforge.net/project/showfiles.php?group_id=122353&amp;package_id=133626" target="_blank">latest ffmpeg-php release</a></li>
<li>Extract the archive:<br />
<code>tar -xjf ffmpeg-php-X.x.x.tbz2</code></li>
<li><code>cd ffmpeg-php-X.x.x/</code></li>
<li><code>phpize</code></li>
<li><code>./configure &amp;&amp; make</code></li>
<li><code>sudo make install</code></li>
</ol>
<h3>Finishing Thoughts</h3>
<p>This may seem like a lot of work when I earlier described this process as &#8220;simple,&#8221; but trust me that this is a thousand times easier than when I first tried installing FFmpeg. I think I spent three hours working on installing FFmpeg just to find out that it didn&#8217;t work the first time I tried.</p>
<p>Time and time again, package management has proven to be an extremely powerful tool. While I know the value of manually configuring and compiling code, the ease of simply using a package manager can reduce the time needed to install and manage software from hours or days to minutes.</p>
<p>I&#8217;m glad to see that FFmpeg has benefited from the use of these package managers and great repositories like the DAG RPM Repository.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/01/13/install-ffmpeg-and-ffmpeg-php-on-centos-easily/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>Convert XML to Associative Array in PHP</title>
		<link>http://chrisjean.com/2009/01/12/convert-xml-to-associative-array-in-php/</link>
		<comments>http://chrisjean.com/2009/01/12/convert-xml-to-associative-array-in-php/#comments</comments>
		<pubDate>Mon, 12 Jan 2009 22:40:58 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=565</guid>
		<description><![CDATA[I&#8217;m working on a project where I needed to convert an XML doc into an associative array in PHP easily. I hadn&#8217;t done any work with XML in PHP yet, so I started digging around the usual places. Soon, it looked like my best option would be to create a completely-custom XML parsing engine out [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>I&#8217;m working on a project where I needed to convert an XML doc into an associative array in PHP easily. I hadn&#8217;t done any work with XML in PHP yet, so I started digging around the usual places.</p>
<p>Soon, it looked like my best option would be to create a completely-custom XML parsing engine out of PHP&#8217;s built-in <a href="http://us2.php.net/xml" target="_blank">XML Parser</a>. I started working on a set of code based off of the <a href="http://us2.php.net/manual/en/example.xml-external-entity.php" target="_blank">External Entity Example</a> since that is the only example that actually incorporates the ability to retrieve data and not just attributes. My results were slow and very error prone. Why is this so tough? XML isn&#8217;t exactly new, and it is very widespread. Similarly, PHP is an extremely popular language. So, why is it so hard to combine the two and work with them easily? I shouldn&#8217;t have to create a custom syntax parser just to be able to read a standard format document into a PHP data structure.</p>
<p><span id="more-565"></span></p>
<p>I started to look around again. That&#8217;s when I found <a href="http://pear.php.net/manual/en/package.xml.xml-parser.intro.php" target="_blank">PEAR&#8217;s XML_Parser</a>. Great! This looks to be just what I want. It deals with all the junk, and tries its best to just let me traverse the document. I started using the examples and quickly realized something, XML_Parser may work great for a document definition that never changes, but I want something that isn&#8217;t rigidly tied down to a very legalistic expectation of data. Is it really so much to ask for just a function that can take the structure and throw it into an associative array so that I don&#8217;t have to recode the parser every time the data format changes?</p>
<p>So, my search began anew. This time, I found something that was perfect: two functions that could either take an associative array and dump out an XML string or take an XML string and dump out an associative array. I was amazed since it was exactly what I was looking for. My pain relief came from <a href="http://www.zend.com//code/codex.php?ozid=982&amp;single=1" target="_blank"><span class="boxheading">XML @=@ Associative Array</span></a><span class="boxheading">.</span></p>
<p><span class="boxheading">Frankly, it looks like ignored code. It&#8217;s been around for nearly seven years on that site, yet it hasn&#8217;t even had 8000 views? What is wrong with people? IMHO, this type of functionality should be directly built into the core of PHP. Now I admit that this code isn&#8217;t everyone&#8217;s cup-o-tea, but it should work for about 95% of people that just want to use the data in an XML file quickly and easily into their code.</span></p>
<p><span class="boxheading">The code itself isn&#8217;t perfect, it doesn&#8217;t do enough checking, so it throws massive amounts of warnings. I also found the naming schemes a bit lacking and some of the formatting not quite to my liking. So, I cleaned it up and modified some of the naming conventions. While I was at it, I added the ability to load XML from a file or URL rather than just from a string. Apparently, this was intended based on the given examples but was never implemented. The code is a bit long to post here, so click the download link below to get the file.</span></p>
<p><a href="http://chrisjean.com/wp-content/uploads/2009/01/xmllibphp.zip">Download zipped xmlLib.php</a></p>
<p>Enjoy.</p>
<h3>2009-02-11 Update</h3>
<p>WordPress autosave fails me again. I had expanded this post by more than 100% with examples and details of the parameter options for each classes&#8217; methods. Unfortunately, Flash crashed my browser. When I loaded back up, all my changes were nowhere to be found.</p>
<p>I guess that the autosave doesn&#8217;t work when you are updating a post. This really should be a feature where modifying a post that has already been published causes new revisions to be saved but not made active. This way I could recover data in the event of a browser crash.</p>
<p>Anyways. I updated the download above. The xmlLib.php file has been updated (check the file for update notes) and I&#8217;ve included a test file that will show you a quick example of how to use the two classes.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/01/12/convert-xml-to-associative-array-in-php/feed/</wfw:commentRss>
		<slash:comments>22</slash:comments>
		</item>
		<item>
		<title>smrsh: &#8220;php&#8221; not available for sendmail programs (stat failed)</title>
		<link>http://chrisjean.com/2009/01/07/smrsh-php-not-available-for-sendmail-programs-stat-failed/</link>
		<comments>http://chrisjean.com/2009/01/07/smrsh-php-not-available-for-sendmail-programs-stat-failed/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 14:31:16 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[bounceback]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Sendmail]]></category>
		<category><![CDATA[Ubersmith]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=499</guid>
		<description><![CDATA[I had to configure Sendmail in order for Ubersmith to be able to receive support requests via email. Basically, you configure an alias (/etc/aliases) like so: support: "&#124;php -q -f /home/html/cron/gateway.php domain.com 1" This all seemed to be very straightforward. I didn&#8217;t even think to test it until hours later. When I finally did test [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>I had to <a href="http://chrisjean.com/2009/01/07/configuring-sendmail-to-receive-external-mail/" target="_blank">configure Sendmail</a> in order for Ubersmith to be able to receive support requests via email. Basically, you configure an alias (/etc/aliases) like so:</p>
<div style="padding-left:30px;"><code>support: "|php -q -f /home/html/cron/gateway.php domain.com 1"</code></div>
<p>This all seemed to be very straightforward. I didn&#8217;t even think to test it until hours later. When I finally did test out the support request by email function, I received this very abrupt rebuke from Sendmail in the form of a bounceback:</p>
<p><span id="more-499"></span></p>
<pre style="padding-left:30px;"> ----- The following addresses had permanent fatal errors -----
"|php -q -f /home/html/cron/gateway.php domain.com 1"
(reason: Service unavailable)
(expanded from: )

----- Transcript of session follows -----
smrsh: "php" not available for sendmail programs (stat failed)
554 5.0.0 Service unavailable</pre>
<p>Not exactly a friendly response.</p>
<p>I dug around a bit and found out that Sendmail places severe limitations on what it has access to. This is actually a good thing since it ensures that you open up possible security holes only if you know what you are doing (or at least think you do).</p>
<p>The solution is to explicitly give permission for Sendmail to not only use PHP but also the gateway.php script. That is done by creating a couple of symbolic links in a special Sendmail folder, <code><strong>/etc/smrsh</strong></code>.</p>
<p>I executed the following code to add these symbolic links:</p>
<div style="padding-left:30px;"><code># ln -s /home/html/cron/gateway.php /etc/smrsh/gateway.php<br />
# ln -s /usr/bin/php /etc/smrsh/php</code></div>
<p>Notice that I had to create one for PHP itself and one for the script that I wanted to run. If you are setting this up for a script of your own, make sure that you adjust the paths for your own specific setup. PHP may be located in another path on your server. You can find the location by running &#8220;<code><strong>which php</strong></code>&#8220;.</p>
<p>After I got this setup, the support emails came in like a charm.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/01/07/smrsh-php-not-available-for-sendmail-programs-stat-failed/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Trouble with Ubersmith, Ioncube, and mb_internal_encoding</title>
		<link>http://chrisjean.com/2009/01/06/trouble-with-ubersmith-ioncube-and-mb_internal_encoding/</link>
		<comments>http://chrisjean.com/2009/01/06/trouble-with-ubersmith-ioncube-and-mb_internal_encoding/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 21:00:20 +0000</pubDate>
		<dc:creator>Chris Jean</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Tips 'n Tricks]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Ioncube]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Ubersmith]]></category>
		<category><![CDATA[yum]]></category>

		<guid isPermaLink="false">http://gaarai.com/?p=485</guid>
		<description><![CDATA[Today I&#8217;m installing Ubersmith, a billing system solution, on a server to test it out. I have to say that Ubersmith has a more complex installation process than I&#8217;m used to these days. I guess that I&#8217;ve been spoiled. Here&#8217;s a quick word about what I&#8217;m running. My test server is a dedicated system running [...]]]></description>
			<content:encoded><![CDATA[<!-- filtered -->
<p>Today I&#8217;m installing <a href="http://www.ubersmith.com/" target="_blank">Ubersmith</a>, a billing system solution, on a server to test it out. I have to say that Ubersmith has a more complex installation process than I&#8217;m used to these days. I guess that I&#8217;ve been spoiled.</p>
<p>Here&#8217;s a quick word about what I&#8217;m running. My test server is a dedicated system running <a href="http://www.centos.org/" target="_blank">CentOS</a> 5.2 64-bit. The software setup is nothing special as most of the packages are straight from the repository.</p>
<p>I loaded the release files on the server, untarred them, and proceeded to read the instructions. Everything looked to be straight-forward. I quickly got down to the part about installing Ioncube. That&#8217;s when the trouble started.</p>
<p><span id="more-485"></span></p>
<p>I followed the instructions for getting Ioncube loaded, quickly modified my php.ini file, and restarted Apache. I then tried to access the site and got nothing. I looked at the logs and found that Ioncube wasn&#8217;t loading while reporting the following error:</p>
<div style="padding-left:30px;"><code>Failed loading /usr/local/ioncube/ioncube_loader_lin_5.1.so:  /usr/local/ioncube/ioncube_loader_lin_5.1.so: wrong ELF class: ELFCLASS32</code></div>
<p>Frankly, I had no idea what that meant. A bit of searching later, I find that I apparently have the wrong Ioncube loader. That didn&#8217;t make any sense since I loaded the exact loader that the ioncube-loader-helper.php program told me to use. I had a hunch that I knew what the problem was and decided to check it out. Yup, Ioncube Loader has 32-bit and 64-bit versions, the problem has to be that the Ubersmith code came with the 32-bit code. I downloaded a Linux (x86-64) archive from <a href="http://www.ioncube.com/loaders.php" target="_blank">the Ioncube Loader packages</a> page, loaded it up, restarted Apache again, and got Ioncube to load properly.</p>
<p>Ioncube was now loaded, but the page still didn&#8217;t render. Looking at the logs, I found this wonderful gem:</p>
<div style="padding-left:30px;"><code>PHP Fatal error:  Call to undefined function mb_internal_encoding() in /home/site/html/include/i18n.boot.php on line 15</code></div>
<p>My first thought was, &#8220;great, the software is broken.&#8221; A quick google later, I found that <code><a href="http://us2.php.net/manual/en/function.mb-internal-encoding.php" target="_blank">mb_internal_encoding</a></code> is part of PHP, but it is not a defaultly included option. I looked around at how to activate or add it, and everyone was going on about needing to recompile PHP. I&#8217;ve compiled everything from simple command-line tools to Apache2, but I always prefer using repository releases as it makes maintenance that much easier, so I was very upset to see that I needed to compile PHP with a new set of options just to run this software.</p>
<p>I was about to give up on Ubersmith altogether when I remembered how many amazing things package management can do. I ran &#8220;<strong><code>yum search mbstring</code></strong>&#8221; and found that there was a package called <code>php-mbstring</code> ready and waiting for me to install it. I ran &#8220;<strong><code>yum install mbstring</code></strong>&#8220;, restarted Apache, and finally the Ubersmith setup wizard was ready for me.</p>
<p>So, there are a few key pieces of wisdom that I have learned from my experience with installing Ubersmith:</p>
<ol>
<li>Don&#8217;t trust that the installation documents/tools give you all the information you need. Ubersmith made a bad assumption that all systems will only require the 32-bit Ioncube while not making any notes that people on 64-bit platforms need to download new software. Ioncube&#8217;s installation helper neglected to check to see if the Ioncube files I had were built to work on my platform, and just like Ubersmith, the helper made no attempt to notify me that I may require different files depending on whether my platform is 32-bit or 64-bit.</li>
<li>Never trust that the third-party software packaged with another piece of software is the correct software for your system. If something breaks, first replace that packaged software with software freshly downloaded from the developer&#8217;s site.</li>
<li>When references say to compile your own software to get something to work, always remember to try using the package management tools first.</li>
</ol>
<p>As I continued on the setup path, this wisdom had immediate use. The setup wizard indicated that two PHP extensions were missing: Mcrypt and XML-RPC. I immediately ran &#8220;<strong><code>yum search mcrypt</code></strong>&#8221; and &#8220;<strong><code>yum search xmlrpc</code></strong>&#8221; which returned positive results. I then ran &#8220;<strong><code>yum install php-mcrypt</code></strong>&#8221; and &#8220;<strong><code>yum install php-xmlrpc</code></strong>&#8221; and was golden. Just think if I had decided on compiling my own version of PHP earlier, I would have finally finished, gotten it working, and then had to do it all over again when I ran the setup and hit this snag. Thank you <a href="http://fedoraproject.org/wiki/Tools/yum" target="_blank">yum</a>.</p>
<p>One thing that I have a gripe about is Ioncube&#8217;s navigation structure. I went to their site looking for download links for Ioncube Loader, and could not find them anywhere. I ended asking Google where I could find Ioncube Loader, and like a good little Google, it was right on the first try. I then tried again to find that page in the nav and found it under <strong>Products &gt; Free Loaders for Encoded Files</strong>. I&#8217;m probably just daft, but I skipped right over that stuff because I was skimming the left side of the nav looking for something that started with &#8220;Ioncube &#8230;&#8221; not &#8220;Free &#8230;&#8221; At the very least, put links on the encoder pages that point to the loader page and say, &#8220;Looking for Ioncube Loader? Click here.&#8221;&lt;/rant&gt;</p>
]]></content:encoded>
			<wfw:commentRss>http://chrisjean.com/2009/01/06/trouble-with-ubersmith-ioncube-and-mb_internal_encoding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

