<?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>Ivan Villareal</title>
	<atom:link href="http://blog.ivanvillareal.info/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ivanvillareal.info</link>
	<description>IT stuff and more...</description>
	<lastBuildDate>Wed, 16 Jun 2010 18:21:30 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>get Name and email address from a &#8220;from&#8221; email header</title>
		<link>http://blog.ivanvillareal.info/development/get-name-and-email-address-from-a-from-email-header/</link>
		<comments>http://blog.ivanvillareal.info/development/get-name-and-email-address-from-a-from-email-header/#comments</comments>
		<pubDate>Wed, 16 Jun 2010 18:21:30 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[from]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[preg]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=268</guid>
		<description><![CDATA[This is a quick post of a little function I did to get the name and the email of a &#8220;from&#8221; header, Because this is not a standard thing this function only recognizes the following format:
Some Name &#60;someemail @server.com&#62;&#60;/someemail&#62;
this is the function I came up:
function extractEmailAddress&#40;$subject&#41;
    &#123;
      [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick post of a little function I did to get the name and the email of a &#8220;from&#8221; header, Because this is not a standard thing this function only recognizes the following format:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Text"><div class="devcodeoverflow">Some Name &lt;someemail @server.com&gt;&lt;/someemail&gt;</div></pre><!--END_DEVFMTCODE--></p>
<p>this is the function I came up:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="PHP"><div class="devcodeoverflow"><span style="color: #000000; font-weight: bold;">function</span> extractEmailAddress<span style="color: #009900;">&#40;</span><span style="color: #000088;">$subject</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> stdClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/\\b[A-Z0-9._%-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}\\b/i'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$regs</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$regs</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #666666; font-style: italic;">//try to get the name</span>
        <span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(.*)&lt; (.*)&gt;/'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$regs</span><span style="color: #339933;">,</span> PREG_PATTERN_ORDER<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$regs</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span>0<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$regs</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$regs</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></div></pre><!--END_DEVFMTCODE--></p>
<p>And this are some results I had:</p>
<p>Case 1:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="PHP"><div class="devcodeoverflow"><span style="color: #000088;">$testName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Ivan Villareal &lt;ivan @server.com&gt;&quot;</span><span style="color: #339933;">;</span>  <span style="color: #339933;">&lt;/</span>ivan<span style="color: #339933;">&gt;</span></div></pre><!--END_DEVFMTCODE--><br />
Result:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Text"><div class="devcodeoverflow">object(stdClass)#3 (2) {
  [&quot;email&quot;]=&gt;
  string(15) &quot;ivan@server.com&quot;
  [&quot;name&quot;]=&gt;
  string(15) &quot;Ivan Villareal &quot;
}
</div></pre><!--END_DEVFMTCODE--></p>
<p>Case 2:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="PHP"><div class="devcodeoverflow"><span style="color: #000088;">$testName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Ivan Villareal ivan@server.com&quot;</span><span style="color: #339933;">;</span> </div></pre><!--END_DEVFMTCODE--><br />
Result:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Text"><div class="devcodeoverflow">object(stdClass)#3 (2) {
  [&quot;email&quot;]=&gt;
  string(15) &quot;ivan@server.com&quot;
  [&quot;name&quot;]=&gt;
  string(0) &quot;&quot;
}
</div></pre><!--END_DEVFMTCODE--></p>
<p>Case 3:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="PHP"><div class="devcodeoverflow"><span style="color: #000088;">$testName</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ivan@server.com&quot;</span><span style="color: #339933;">;</span></div></pre><!--END_DEVFMTCODE--><br />
Result:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Text"><div class="devcodeoverflow">object(stdClass)#3 (2) {
  [&quot;email&quot;]=&gt;
  string(15) &quot;ivan@server.com&quot;
  [&quot;name&quot;]=&gt;
  string(0) &quot;&quot;
}
</div></pre><!--END_DEVFMTCODE--></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/development/get-name-and-email-address-from-a-from-email-header/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fetching mail from a POP3 server with Zend_Mail</title>
		<link>http://blog.ivanvillareal.info/development/fetching-mail-from-a-pop3-server-with-zend_mail/</link>
		<comments>http://blog.ivanvillareal.info/development/fetching-mail-from-a-pop3-server-with-zend_mail/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 01:09:05 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[fetching mail]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[pop]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Zend_Mail]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=258</guid>
		<description><![CDATA[I was in a need for a class to get mails from a pop server to process them, so I’ve decided to leverage the Zend_Mail class, what I did was to create a wrapper around the Zend_Mail, to return all the messages from the server in a manageable way.
The first step was to put the [...]]]></description>
			<content:encoded><![CDATA[<p>I was in a need for a class to get mails from a pop server to process them, so I’ve decided to leverage the Zend_Mail class, what I did was to create a wrapper around the Zend_Mail, to return all the messages from the server in a manageable way.</p>
<p>The first step was to put the needed Zend files in my library folder:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Text"><div class="devcodeoverflow">
lib/Zend/Mail.php
Mail
|-- Exception.php
|-- Message
|   |-- File.php
|   `-- Interface.php
|-- Message.php
|-- Part
|   |-- File.php
|   `-- Interface.php
|-- Part.php
|-- Protocol
|   |-- Abstract.php
|   |-- Exception.php
|   |-- Imap.php
|   |-- Pop3.php
|   |-- Smtp
|   |   `-- Auth
|   |       |-- Crammd5.php
|   |       |-- Login.php
|   |       `-- Plain.php
|   `-- Smtp.php
|-- Storage
|   |-- Abstract.php
|   |-- Exception.php
|   |-- Folder
|   |   |-- Interface.php
|   |   |-- Maildir.php
|   |   `-- Mbox.php
|   |-- Folder.php
|   |-- Imap.php
|   |-- Maildir.php
|   |-- Mbox.php
|   |-- Pop3.php
|   `-- Writable
|       |-- Interface.php
|       `-- Maildir.php
|-- Storage.php
`-- Transport
    |-- Abstract.php
    |-- Exception.php
    |-- Sendmail.php
    `-- Smtp.php
</div></pre><!--END_DEVFMTCODE--></p>
<p>Then I started writing my class:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="PHP"><div class="devcodeoverflow"><span style="color: #339933;">&lt;</span> ?php
&nbsp;
<span style="color: #990000;">set_include_path</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'lib'</span> <span style="color: #339933;">.</span> PATH_SEPARATOR <span style="color: #339933;">.</span> <span style="color: #990000;">get_include_path</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">include_once</span> <span style="color: #0000ff;">'Zend/Mail.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include_once</span> <span style="color: #0000ff;">'Zend/Mail/Storage/Pop3.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include_once</span> <span style="color: #0000ff;">'Zend/Mail/Transport/Smtp.php'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include_once</span> <span style="color: #0000ff;">'Zend/Mime/Part.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009933; font-style: italic;">/**</span>
<span style="color: #009933; font-style: italic;">&nbsp;* Class to get mails from a server</span>
<span style="color: #009933; font-style: italic;">&nbsp;*/</span>
<span style="color: #000000; font-weight: bold;">class</span> mailFetcher
<span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_emailHost</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'pop.server.com'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_emailUser</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'ivan@ivanvillareal.com'</span><span style="color: #339933;">;</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_emailPass</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'password'</span><span style="color: #339933;">;</span>
	<span style="color: #009933; font-style: italic;">/**</span>
<span style="color: #009933; font-style: italic;">	 * Zend_Mail_Storage</span>
<span style="color: #009933; font-style: italic;">	 */</span>
    <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_mail</span><span style="color: #339933;">;</span>
	<span style="color: #009933; font-style: italic;">/**</span>
<span style="color: #009933; font-style: italic;">	 * Inbox wrapper</span>
<span style="color: #009933; font-style: italic;">	 */</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_inbox</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**</span>
<span style="color: #009933; font-style: italic;">	 * on class instantiation we fire connect</span>
<span style="color: #009933; font-style: italic;">	 * to the pop server and start fetching the mails</span>
<span style="color: #009933; font-style: italic;">	 */</span>
    <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        try <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_mail <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Mail_Storage_Pop3<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
                                             <span style="color: #0000ff;">'host'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_emailHost<span style="color: #339933;">,</span>
                                             <span style="color: #0000ff;">'user'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_emailUser<span style="color: #339933;">,</span>
                                             <span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_emailPass<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'Mail Retrieval Failed...'</span> <span style="color: #339933;">.</span> PHP_EOL<span style="color: #339933;">;</span>
            <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>      
        <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">processMail</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _contentDecoder<span style="color: #009900;">&#40;</span><span style="color: #000088;">$encoding</span><span style="color: #339933;">,</span> <span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$encoding</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'quoted-printable'</span><span style="color: #339933;">:</span>
				<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">quoted_printable_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'base64'</span><span style="color: #339933;">:</span>
				<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #990000;">base64_decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span>
				<span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$content</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #009933; font-style: italic;">/**</span>
<span style="color: #009933; font-style: italic;">	 * This is where everything is done</span>
<span style="color: #009933; font-style: italic;">	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> processMail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_mail instanceof Zend_Mail_Storage_Pop3 <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_mail<span style="color: #339933;">-&gt;</span><span style="color: #004000;">countMessages</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&gt;</span> 0<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$messageNum</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
			<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_mail <span style="color: #b1b100;">as</span> <span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #000088;">$messageNum</span><span style="color: #339933;">++;</span>
				<span style="color: #000088;">$rawMail</span>      <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_mail<span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRawHeader</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$messageNum</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_mail<span style="color: #339933;">-&gt;</span><span style="color: #004000;">getRawContent</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$messageNum</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$received</span>     <span style="color: #339933;">=</span> <span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">received</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$date</span>         <span style="color: #339933;">=</span> <span style="color: #990000;">date</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Y-m-d H:i:s'</span><span style="color: #339933;">,</span> <span style="color: #990000;">strtotime</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">date</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$messageId</span>    <span style="color: #339933;">=</span> <span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">headerExists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'message-id'</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'message-id'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">//remove &lt;&gt; from message id</span>
				<span style="color: #000088;">$messageId</span>    <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'|&lt; (.*?)&gt;|'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$messageId</span><span style="color: #339933;">,</span> <span style="color: #000088;">$regs</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$regs</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$messageId</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$inReplyTo</span>    <span style="color: #339933;">=</span> <span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">headerExists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'in-reply-to'</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'in-reply-to'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">//remove &lt;&gt; from in-reply-to</span>
				<span style="color: #000088;">$inReplyTo</span>    <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'|&lt; (.*?)&gt;|'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$inReplyTo</span><span style="color: #339933;">,</span> <span style="color: #000088;">$regs</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$regs</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$inReplyTo</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$references</span>   <span style="color: #339933;">=</span> <span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">headerExists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'References'</span><span style="color: #009900;">&#41;</span>  ? <span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'References'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
				<span style="color: #666666; font-style: italic;">//remove &lt;&gt; from references</span>
				<span style="color: #000088;">$references</span>   <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">preg_match</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'|&lt; (.*?)&gt;|'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$references</span><span style="color: #339933;">,</span> <span style="color: #000088;">$regs</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$regs</span><span style="color: #009900;">&#91;</span>1<span style="color: #009900;">&#93;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$references</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$from</span>         <span style="color: #339933;">=</span> <span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$subject</span>      <span style="color: #339933;">=</span> <span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">subject</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$to</span>           <span style="color: #339933;">=</span> <span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">to</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$plainContent</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$htmlContent</span>  <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
				<span style="color: #000088;">$attachments</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #009933; font-style: italic;">/**</span>
<span style="color: #009933; font-style: italic;">				 * Check if the message has multiple parts</span>
<span style="color: #009933; font-style: italic;">				 */</span>
		        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">isMultipart</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #009933; font-style: italic;">/**</span>
<span style="color: #009933; font-style: italic;">					 * We have a multipart message</span>
<span style="color: #009933; font-style: italic;">					 * lets extract the plain content,</span>
<span style="color: #009933; font-style: italic;">					 * html content, and attachments</span>
<span style="color: #009933; font-style: italic;">					 */</span>
					<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> RecursiveIteratorIterator<span style="color: #009900;">&#40;</span><span style="color: #000088;">$message</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$part</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						try <span style="color: #009900;">&#123;</span>
							<span style="color: #b1b100;">switch</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">strtok</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$part</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">contentType</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">';'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
								<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'text/plain'</span><span style="color: #339933;">:</span>
									<span style="color: #000088;">$plainContent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_contentDecoder<span style="color: #009900;">&#40;</span><span style="color: #000088;">$part</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'content-transfer-encoding'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$part</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
								<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
								<span style="color: #b1b100;">case</span> <span style="color: #0000ff;">'text/html'</span><span style="color: #339933;">:</span>
									<span style="color: #000088;">$htmlContent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_contentDecoder<span style="color: #009900;">&#40;</span><span style="color: #000088;">$part</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'content-transfer-encoding'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$part</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
								<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
								<span style="color: #b1b100;">default</span><span style="color: #339933;">:</span> <span style="color: #666666; font-style: italic;">//attachment handle</span>
									<span style="color: #000088;">$type</span>       <span style="color: #339933;">=</span> <span style="color: #990000;">strtok</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$part</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">contentType</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">';'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
									<span style="color: #000088;">$fileName</span>   <span style="color: #339933;">=</span> <span style="color: #000088;">$part</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'content-description'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
									<span style="color: #000088;">$attachment</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_contentDecoder<span style="color: #009900;">&#40;</span><span style="color: #000088;">$part</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getHeader</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'content-transfer-encoding'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$part</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
									<span style="color: #000088;">$attachments</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
													   <span style="color: #0000ff;">'file_name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$fileName</span><span style="color: #339933;">,</span>
													   <span style="color: #0000ff;">'type'</span>      <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$type</span><span style="color: #339933;">,</span>
													   <span style="color: #0000ff;">'content'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$attachment</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
								<span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
							<span style="color: #009900;">&#125;</span>
						<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Zend_Mail_Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
							<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$e</span> <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000088;">$plainContent</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$message</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getContent</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				<span style="color: #009900;">&#125;</span>
				<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_inbox<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'messageNumber'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$messageNum</span><span style="color: #339933;">,</span>
									    <span style="color: #0000ff;">'rawMail'</span>       <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$rawMail</span><span style="color: #339933;">,</span>
										<span style="color: #0000ff;">'received'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$received</span><span style="color: #339933;">,</span>
										<span style="color: #0000ff;">'date'</span>			<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$date</span><span style="color: #339933;">,</span>
										<span style="color: #0000ff;">'messageId'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$messageId</span><span style="color: #339933;">,</span>
										<span style="color: #0000ff;">'inReplyTo'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$inReplyTo</span><span style="color: #339933;">,</span>
										<span style="color: #0000ff;">'references'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$references</span><span style="color: #339933;">,</span>
										<span style="color: #0000ff;">'from'</span>			<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$from</span><span style="color: #339933;">,</span>
										<span style="color: #0000ff;">'subject'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span>
										<span style="color: #0000ff;">'to'</span>			<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$to</span><span style="color: #339933;">,</span>
										<span style="color: #0000ff;">'plainContent'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$plainContent</span><span style="color: #339933;">,</span>
										<span style="color: #0000ff;">'htmlContent'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$htmlContent</span><span style="color: #339933;">,</span>
										<span style="color: #0000ff;">'attachments'</span>	<span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$attachments</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_inbox <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> getInbox<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_inbox<span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></div></pre><!--END_DEVFMTCODE--></p>
<p>My fetch class does everything on instantiation, and it will have all the mails retreived, so for example if I need to get all messages I can do this:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="PHP"><div class="devcodeoverflow"><span style="color: #339933;">&lt;</span> ?php
<span style="color: #b1b100;">include_once</span> <span style="color: #0000ff;">'mailFetcher.php'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$inbox</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> mailFetcher<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$inbox</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getInbox</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></pre><!--END_DEVFMTCODE--></p>
<p>And this would be the result:<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Text"><div class="devcodeoverflow">Array
(
    [0] =&gt; Array
        (
            [messageNumber] =&gt; 1
            [rawMail] =&gt; Received: from gate55.gate.iad.mailserver.com (11.1.111.1) by
 IAD2HUB01.mex02.mailserver.com (111.11.11.65) with Microsoft SMTP Server (TLS) id
 8.2.247.2; Wed, 9 Jun 2010 17:56:16 -0400
Received: from mail-yw0-f186.google.com (mail-yw0-f186.google.com
 [111.11.111.186])	by gate55.gate.iad.mailserver.com (SMTP Server) with ESMTP id
 B1F6E31D0171	for &lt;asdfasdf @ivanvillareal.com&gt;; Wed,  9 Jun 2010
 17:56:15 -0400 (EDT)
Received: by ywh16 with SMTP id 16so5309053ywh.32        for
 &lt;/asdfasdf&gt;&lt;asdfasdf @ivanvillareal.com&gt;; Wed, 09 Jun 2010 14:56:15 -0700 (PDT)
Received: by 10.111.111.111 with SMTP id jz1mr465966qcb.170.1276120573865;
 	Wed, 09 Jun 2010 14:56:13 -0700 (PDT)
Received: by 11.111.111.11 with HTTP; Wed, 9 Jun 2010 14:56:13 -0700 (PDT)
From: Ivan Villareal &lt;ivaano @gmail.com&gt;
To: &quot;asdfasdf@ivanvillareal.com&quot; &lt;asdfasdf @ivanvillareal.com&gt;
Date: Wed, 9 Jun 2010 17:56:13 -0400
Subject: attachment test
Thread-Topic: attachment test
Thread-Index: AcsIHpXuE+vWJJMfTGyqikgD2kYkng==
Message-ID: &lt;aanlktingkmpbkefog5kxxoq8wrib7tj1pt1rsy -1ug-1@mail.gmail.com&gt;
Accept-Language: en-US
Content-Language: en-US
X-MS-Exchange-Organization-AuthAs: Anonymous
X-MS-Exchange-Organization-AuthSource: IAD2HUB01.mex02.mailserver.com
X-MS-Has-Attach: yes
X-MS-TNEF-Correlator:
x-virus-scanned: OK, catchall
x-originating-ip: [111.11.111.186]
dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed;        d=gmail.com;
 s=gamma;
        h=domainkey-signature:mime-version:received:received:date:message-id
         :subject:from:to:content-type;
        bh=IvMOHmKRabcJ2PrUHPHB/NbNpgQubvvgGprC6gtDY9E=;
        b=cA5Pjycedt9Pylic7CTk4HCF6HXV9eEFpr086KwcMepGKJEv4DWU6d4iFt4Gp7R42V
         +4rVmrmwj2j9yj1vbEUqVMI6/m+Kkwt1r+MAtN/0qZsvEaVBBbbjTBxFLO9cQ7xlaSSm
         eGTHv9mR0qCcBZGLOVFeWUNiYDkhY2F0eDUbU=
domainkey-signature: a=rsa-sha1; c=nofws;        d=gmail.com; s=gamma;
        h=mime-version:date:message-id:subject:from:to:content-type;
        b=VKdlRSfBz/Swij0xE0c7Su8TOwcc2YGmw0K8dvVxoS9TJf0p8nIqtR6nQtmKqabSu4
         g2ALFFHXuVOhGpP+JdvI3wQJ1k9N5EZhcWtSRECrikOlLnaDA8/4z3SYckY6hs7Q+KIe
         qG0IbY+QkuZh7yymcyAN5omTaFDFT2GIPs+1c=
x-orig-to: catchall@ivanvillareal.com
Content-Type: multipart/mixed;
	boundary=&quot;_004_AANLkTingkMPbKeFog5kxXoq8WRib7tJ1pT1Rsy1ug1mailgmailcom_&quot;
MIME-Version: 1.0
&nbsp;
--_004_AANLkTingkMPbKeFog5kxXoq8WRib7tJ1pT1Rsy1ug1mailgmailcom_
Content-Type: multipart/alternative;
	boundary=&quot;_000_AANLkTingkMPbKeFog5kxXoq8WRib7tJ1pT1Rsy1ug1mailgmailcom_&quot;
&nbsp;
--_000_AANLkTingkMPbKeFog5kxXoq8WRib7tJ1pT1Rsy1ug1mailgmailcom_
Content-Type: text/plain; charset=&quot;utf-8&quot;
Content-Transfer-Encoding: base64
&nbsp;
amhnamhnamhnDQo=
&nbsp;
--_000_AANLkTingkMPbKeFog5kxXoq8WRib7tJ1pT1Rsy1ug1mailgmailcom_
Content-Type: text/html; charset=&quot;utf-8&quot;
Content-Transfer-Encoding: base64
&nbsp;
amhnamhnamhnDQo=
&nbsp;
--_000_AANLkTingkMPbKeFog5kxXoq8WRib7tJ1pT1Rsy1ug1mailgmailcom_--
&nbsp;
--_004_AANLkTingkMPbKeFog5kxXoq8WRib7tJ1pT1Rsy1ug1mailgmailcom_
Content-Type: image/jpeg; name=&quot;2010-05-28-112655.jpg&quot;
Content-Description: 2010-05-28-112655.jpg
Content-Disposition: attachment; filename=&quot;2010-05-28-112655.jpg&quot;; size=15004;
	creation-date=&quot;Wed, 09 Jun 2010 17:56:16 GMT&quot;;
	modification-date=&quot;Wed, 09 Jun 2010 17:56:16 GMT&quot;
Content-Transfer-Encoding: base64
&nbsp;
/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0a
gq4UlFJmmKwtHakzS0DsMNFLikIxQAUmKKM0AFLSUtABRRRQAlFGeaKACiikouAtGaKPrQAmaKDS
4oASgClxRQKwUUUlAxaKKM0AFBNFGM0AGalHzIKiIp6HgigQuKKKKQyZDlaJAcU2I09+VP0qWSRK
R0zTGXBpuec1IDvX3qihqNhhV5WG0Vn9DUocgUMTJpyCpIqsKezZXmoqENDqQ0dqBmmMBS0UmKAF
oFJS0AJ3oIpQKQk0AAp4JxTBTxQwYE0oFNNOU8UhCkDGKaRin0EZoEiLIpcUuzuKMUyrje9FKQet
J2oGf//Z
&nbsp;
--_004_AANLkTingkMPbKeFog5kxXoq8WRib7tJ1pT1Rsy1ug1mailgmailcom_--
&nbsp;
            [received] =&gt; from gate55.gate.iad.mailserver.com (11.1.111.1) by IAD2HUB01.mex02.mailserver.com (111.11.11.15) with Microsoft SMTP Server (TLS) id 1.1.147.2; Wed, 9 Jun 2010 17:56:16 -0400
from mail-yw0-f186.google.com (mail-yw0-f186.google.com [209.85.211.186])	by gate55.gate.iad.mailserver.com (SMTP Server) with ESMTP id B1F6E31D0171	for &lt;asdfasdf @ivanvillareal.com&gt;; Wed,  9 Jun 2010 17:56:15 -0400 (EDT)
by ywh16 with SMTP id 16so5309053ywh.32        for &lt;/asdfasdf&gt;&lt;asdfasdf @ivanvillareal.com&gt;; Wed, 09 Jun 2010 14:56:15 -0700 (PDT)
by 10.229.233.193 with SMTP id jz1mr465966qcb.170.1276120573865; Wed, 09 Jun 2010 14:56:13 -0700 (PDT)
by 10.229.192.82 with HTTP; Wed, 9 Jun 2010 14:56:13 -0700 (PDT)
            [date] =&gt; 2010-06-09 14:56:13
            [messageId] =&gt; AANLkTingkMPbKeFog5kxXoq8WRib7tJ1pT1Rsy-1ug-1@mail.gmail.com
            [inReplyTo] =&gt; 
            [references] =&gt; 
            [from] =&gt; Ivan Villareal &lt;ivaano @gmail.com&gt;
            [subject] =&gt; attachment test
            [to] =&gt; &quot;asdfasdf@ivanvillareal.com&quot; &lt;asdfasdf @ivanvillareal.com&gt;
            [plainContent] =&gt; jhgjhgjhg
&nbsp;
            [htmlContent] =&gt; jhgjhgjhg
&nbsp;
            [attachments] =&gt; Array
                (
                    [0] =&gt; Array
                        (
                            [file_name] =&gt; 2010-05-28-112655.jpg
                            [type] =&gt; image/jpeg
                        )
&nbsp;
                )
&nbsp;
        )
&nbsp;
)&lt;/asdfasdf&gt;&lt;/ivaano&gt;&lt;/asdfasdf&gt;&lt;/aanlktingkmpbkefog5kxxoq8wrib7tj1pt1rsy&gt;&lt;/asdfasdf&gt;&lt;/ivaano&gt;&lt;/asdfasdf&gt;</div></pre><!--END_DEVFMTCODE--></p>
<p>From this point I can iterate the inbox easily saving the email results or applying other logic to it, </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/development/fetching-mail-from-a-pop3-server-with-zend_mail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache virtual host script in perl</title>
		<link>http://blog.ivanvillareal.info/linux/apache-virtual-host-script-in-perl/</link>
		<comments>http://blog.ivanvillareal.info/linux/apache-virtual-host-script-in-perl/#comments</comments>
		<pubDate>Thu, 27 May 2010 23:57:26 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[configuration]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=250</guid>
		<description><![CDATA[This is a very short post about a little script I did to create remove virtual hosts easily.
I&#8217;ve found a couple of scripts (http://patrickgibson.com/utilities/virtualhost/, http://www.tamdenholm.com/portfolio/apache)&#160; to do this but they didn&#8217;t worked right, I&#8217;m using Ubuntu Karmic, maybe thats why. However instead of fixing those scripts I went to my vim editor and started typing [...]]]></description>
			<content:encoded><![CDATA[<p>This is a very short post about a little script I did to create remove virtual hosts easily.</p>
<p>I&#8217;ve found a couple of scripts (http://patrickgibson.com/utilities/virtualhost/, http://www.tamdenholm.com/portfolio/apache)&nbsp; to do this but they didn&#8217;t worked right, I&#8217;m using Ubuntu Karmic, maybe thats why. However instead of fixing those scripts I went to my vim editor and started typing this, I&#8217;ve spent about 2 hours writing this while I was watching a crappy tv program, but in the end it worked, it surely contains some bugs, or it is unsafe to run it, I just wanted to share this.</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Perl"><div class="devcodeoverflow"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl -w</span>
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> File<span style="color: #339933;">::</span><span style="color: #006600;">Path</span> <span style="color: #000066;">qw</span><span style="color: #009900;">&#40;</span>mkpath rmtree<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> Getopt<span style="color: #339933;">::</span><span style="color: #006600;">Long</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$ipAddress</span>        <span style="color: #339933;">=</span> <span style="color: #ff0000;">'127.0.0.1'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$apacheConfigFile</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'apache2.conf'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$apacheConfigDir</span>  <span style="color: #339933;">=</span> <span style="color: #ff0000;">'/etc/apache2'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$sitesAvailable</span>   <span style="color: #339933;">=</span> <span style="color: #ff0000;">'sites-available'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$docRootPrefix</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'/home/ivan/www'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$docRoot</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">'public_html'</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$logsDir</span>  <span style="color: #339933;">=</span> <span style="color: #ff0000;">'logs'</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$del</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">''</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$add</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">''</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$domain</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">''</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">unless</span> <span style="color: #009900;">&#40;</span>GetOptions <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'del'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">\$del</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'add'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">\$add</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'domain=s'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">\$domain</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">or</span> usage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    usage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#print $paramResults;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$add</span> <span style="color: #339933;">||</span> <span style="color: #0000ff;">$del</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$domain</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$add</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            createVhost<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$domain</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elsif</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$del</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            deleteVhost<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$domain</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        usage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
   <span style="color: #666666; font-style: italic;">#print 'add aqui';</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    usage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> usage <span style="color: #009900;">&#123;</span>
    <span style="color: #000066;">print</span> <span style="color: #339933;">&lt;</span> <span style="color: #339933;">&lt;</span>USAGE
This program will add <span style="color: #b1b100;">or</span> remove
apache virtual hosts on ubuntu karmic 9<span style="color: #339933;">.</span>10
&nbsp;
usage<span style="color: #339933;">:</span> vhost<span style="color: #339933;">-</span>updater<span style="color: #339933;">.</span>pl <span style="color: #009900;">&#91;</span><span style="color: #339933;">--</span>add <span style="color: #339933;">|</span> <span style="color: #339933;">--</span>del<span style="color: #009900;">&#93;</span> <span style="color: #339933;">--</span>domain newhost<span style="color: #339933;">.</span>tld 
USAGE
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> returnVhostPaths
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$vhost</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@dir</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\//</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$docRootPrefix</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%res</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@dir</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$vhost</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$hostDir</span> <span style="color: #339933;">=</span> <span style="color: #000066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">@dir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$res</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'docRoot'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$hostDir</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$docRoot</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$res</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'logsDir'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$hostDir</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">'/'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">$logsDir</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #666666; font-style: italic;">#todo dir validation</span>
    <span style="color: #0000ff;">@dir</span> <span style="color: #339933;">=</span> <span style="color: #000066;">split</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/\//</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$apacheConfigDir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@dir</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$sitesAvailable</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">@dir</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$vhost</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$res</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'apacheConfig'</span><span style="color: #009900;">&#125;</span> <span style="color: #339933;">=</span> <span style="color: #000066;">join</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'/'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">@dir</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">return</span> <span style="color: #0000ff;">%res</span><span style="color: #339933;">;</span>   
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> createVhost <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$vhost</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">#first create the docRoot</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%vhostInfo</span> <span style="color: #339933;">=</span> returnVhostPaths<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vhost</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    informOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Creating docroot dir: $vhostInfo{'docRoot'}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    informOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Creating log dir: $vhostInfo{'logsDir'}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    mkpath<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vhostInfo</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'docRoot'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$vhostInfo</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'logsDir'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
    informOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Site File: $vhostInfo{'apacheConfig'}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$vhostContent</span> <span style="color: #339933;">=</span> <span style="color: #cc0000; font-style: italic;">&lt;&lt; &quot;EOF&quot;;</span>
<span style="color: #cc0000; font-style: italic;">&lt;VirtualHost *:80&gt;</span>
<span style="color: #cc0000; font-style: italic;">&nbsp;   ServerName $vhost</span>
<span style="color: #cc0000; font-style: italic;">&nbsp;   DocumentRoot $vhostInfo{'docRoot'}</span>
<span style="color: #cc0000; font-style: italic;">&nbsp;   &lt;directory $vhostInfo{'docRoot'}&gt;</span>
<span style="color: #cc0000; font-style: italic;">&nbsp;       Options Indexes FollowSymLinks</span>
<span style="color: #cc0000; font-style: italic;">&nbsp;       AllowOverride All</span>
<span style="color: #cc0000; font-style: italic;">&nbsp;       Order allow,deny</span>
<span style="color: #cc0000; font-style: italic;">&nbsp;       Allow from all</span>
<span style="color: #cc0000; font-style: italic;">&nbsp;   &lt;/directory&gt;</span>
<span style="color: #cc0000; font-style: italic;">&nbsp;       ErrorLog $vhostInfo{'logsDir'}/error_log</span>
<span style="color: #cc0000; font-style: italic;">&nbsp;       CustomLog $vhostInfo{'logsDir'}/access_log &quot;%h %l %u %t \\&quot;%r\\&quot; %&gt;s %b \\&quot;%{Referer}i\\&quot; \\&quot;%{User-agent}i\\&quot;&quot;</span>
<span style="color: #cc0000; font-style: italic;">&nbsp;       LogLevel debug</span>
&nbsp;
&nbsp;
<span style="color: #cc0000; font-style: italic;">EOF</span>
    informOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Creating Vhost...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">open</span> FILE<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$vhostInfo</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'apacheConfig'</span><span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #0000ff;">$!</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">print</span> FILE <span style="color: #0000ff;">$vhostContent</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">close</span> FILE<span style="color: #339933;">;</span>
&nbsp;
    informOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Adding host $vhost&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">open</span> FILE<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&gt;&gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'/etc/hosts'</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #0000ff;">$!</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">print</span> FILE <span style="color: #0000ff;">$ipAddress</span> <span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\t</span>&quot;</span><span style="color: #339933;">.</span> <span style="color: #0000ff;">$vhost</span> <span style="color: #339933;">.</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">close</span> FILE<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$output</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">`/usr/sbin/a2ensite $vhost`</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">print</span> <span style="color: #0000ff;">$output</span><span style="color: #339933;">;</span>
&nbsp;
    restartApache<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #666666; font-style: italic;">#print $vhostConten t;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> restartApache
<span style="color: #009900;">&#123;</span>
    informOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Restarting apache&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$output</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">`/etc/init.d/apache2 restart`</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">print</span> <span style="color: #0000ff;">$output</span><span style="color: #339933;">;</span> 
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> deleteVhost
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$vhost</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
     <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">%vhostInfo</span> <span style="color: #339933;">=</span> returnVhostPaths<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vhost</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    informOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Removing $vhost from hosts file&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">open</span> IN<span style="color: #339933;">,</span> <span style="color: #ff0000;">'&lt; '</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'/etc/hosts'</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #0000ff;">$!</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@hostsFile</span> <span style="color: #339933;">=</span> <span style="color: #009999;">&lt;IN&gt;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">close</span> IN<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">@contents</span> <span style="color: #339933;">=</span> <span style="color: #000066;">grep</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!/^</span>127<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>1<span style="color: #0000ff;">\t</span><span style="color: #0000ff;">$vhost</span><span style="color: #339933;">/,</span> <span style="color: #0000ff;">@hostsFile</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">open</span> FILE<span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;&gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'/etc/hosts'</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span> <span style="color: #0000ff;">$!</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">print</span> FILE <span style="color: #0000ff;">@contents</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">close</span> FILE<span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$output</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">`/usr/sbin/a2dissite $vhost`</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">print</span> <span style="color: #0000ff;">$output</span><span style="color: #339933;">;</span>
&nbsp;
    informOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Removing  $vhostInfo{'apacheConfig'} file&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">unlink</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$vhostInfo</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'apacheConfig'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    restartApache<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot; manually remove $vhostInfo{'docRoot'}... <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">sub</span> informOut <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$message</span> <span style="color: #339933;">=</span> <span style="color: #000066;">shift</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;$message <span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></div></pre><!--END_DEVFMTCODE--></p>
<p>Here is a screenshot of the program running</p>
<p><a href="http://blog.ivanvillareal.info/wp-content/uploads/2010/05/Screenshot.png"><img class="aligncenter size-full wp-image-255" title="vhost creator Screenshot" src="http://blog.ivanvillareal.info/wp-content/uploads/2010/05/Screenshot.png" alt="vhost creator Screenshot" width="1024" height="600" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/linux/apache-virtual-host-script-in-perl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bulk domain name resolver with perl</title>
		<link>http://blog.ivanvillareal.info/development/bulk-domain-name-resolver-with-perl/</link>
		<comments>http://blog.ivanvillareal.info/development/bulk-domain-name-resolver-with-perl/#comments</comments>
		<pubDate>Fri, 07 May 2010 10:00:00 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[dbi]]></category>
		<category><![CDATA[name resolver]]></category>
		<category><![CDATA[name to ip]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[sockets]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=239</guid>
		<description><![CDATA[I was in the need of getting the ip address from a long list of domain names, the domains were stored in a MySQL db, so I quickly turned into perl for making a script that got the list and then use an external command to resolve the domain.
At first I was going to use [...]]]></description>
			<content:encoded><![CDATA[<p>I was in the need of getting the ip address from a long list of domain names, the domains were stored in a MySQL db, so I quickly turned into perl for making a script that got the list and then use an external command to resolve the domain.</p>
<p>At first I was going to use the dig command, but that would have taken to much effort, then I thought about using the ping command, but again to much effort, instead I’ve decided to leverage the <a href="http://search.cpan.org/~gbarr/IO-1.25/lib/IO/Socket/INET.pm" target="_blank">IO::Socket::INET</a> module, trying to open a socket to a domain name, will resolve the name and I could use that.</p>
<p>My implementation was very simple and it worked well, here is the relevant part:</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Perl"><div class="devcodeoverflow"><span style="color: #666666; font-style: italic;">#include the module</span>
<span style="color: #000000; font-weight: bold;">use</span> IO<span style="color: #339933;">::</span><span style="color: #006600;">Socket</span><span style="color: #339933;">::</span><span style="color: #006600;">INET</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#create a socket to uncommon udp port, because tcp is likely to be firewalled</span>
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$sock</span> <span style="color: #339933;">=</span> IO<span style="color: #339933;">::</span><span style="color: #006600;">Socket</span><span style="color: #339933;">::</span><span style="color: #006600;">INET</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span>
                           PeerAddr<span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">&quot;$domain&quot;</span><span style="color: #339933;">,</span>
                           PeerPort <span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">40125</span><span style="color: #339933;">,</span>
                           Proto<span style="color: #339933;">=&gt;</span><span style="color: #ff0000;">'udp'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#if we can create a socket, then we have an ip</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">defined</span> <span style="color: #0000ff;">$sock</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #0000ff;">$result</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$sock</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">peerhost</span><span style="color: #339933;">;</span>
         logOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Success!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        logOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Failed trying to connect to $domain&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">return</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></div></pre><!--END_DEVFMTCODE--></p>
<p>&nbsp;</p>
<p>This was Pretty simple no?, here is the complete script, which gathers all the rows with no ip address and then it will try to get the ip, update the row and continue.</p>
<p>&nbsp;</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Perl"><div class="devcodeoverflow"><span style="color: #666666; font-style: italic;">#!/usr/bin/perl</span>
<span style="color: #000000; font-weight: bold;">use</span> strict<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> DBI<span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">use</span> IO<span style="color: #339933;">::</span><span style="color: #006600;">Socket</span><span style="color: #339933;">::</span><span style="color: #006600;">INET</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">####Global Variables###</span>
&nbsp;
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">%db</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'host'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'localhost'</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'domains'</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'user'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'ivan'</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'pass'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'1234'</span><span style="color: #339933;">,</span><span style="color: #ff0000;">'port'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">'3306'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$dsn</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">our</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#log function</span>
<span style="color: #000000; font-weight: bold;">sub</span> logOut <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$msg</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
    <span style="color: #000066;">print</span> <span style="color: #0000ff;">$msg</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#db connection</span>
<span style="color: #000000; font-weight: bold;">sub</span> initialize <span style="color: #009900;">&#123;</span>
    logOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Connecting to db server on $db{'host'}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$dsn</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;DBI:mysql:database=$db{'name'};host=$db{'host'};port=$db{'port'}&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #0000ff;">$dbh</span> <span style="color: #339933;">=</span> DBI<span style="color: #339933;">-&gt;</span><span style="color: #006600;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$dsn</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$db</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'user'</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$db</span><span style="color: #009900;">&#123;</span><span style="color: #ff0000;">'pass'</span><span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">or</span> <span style="color: #000066;">die</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">'failed to connect'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#function to gather the ip fo a domain</span>
<span style="color: #000000; font-weight: bold;">sub</span> getIpAddress <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$domain</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">@_</span><span style="color: #339933;">;</span>
    logOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Trying to connect to: $domain...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$result</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$sock</span> <span style="color: #339933;">=</span> IO<span style="color: #339933;">::</span><span style="color: #006600;">Socket</span><span style="color: #339933;">::</span><span style="color: #006600;">INET</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span>
                           PeerAddr<span style="color: #339933;">=&gt;</span> <span style="color: #ff0000;">&quot;$domain&quot;</span><span style="color: #339933;">,</span>
                           PeerPort <span style="color: #339933;">=&gt;</span><span style="color: #cc66cc;">40125</span><span style="color: #339933;">,</span>
                           Proto<span style="color: #339933;">=&gt;</span><span style="color: #ff0000;">'udp'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">defined</span> <span style="color: #0000ff;">$sock</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
         <span style="color: #0000ff;">$result</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$sock</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">peerhost</span><span style="color: #339933;">;</span>
         logOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Success!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
        logOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Failed trying to connect to $domain&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000066;">return</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066;">return</span> <span style="color: #0000ff;">$result</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">##This function</span>
<span style="color: #666666; font-style: italic;"># gets all domains from domains table</span>
<span style="color: #000000; font-weight: bold;">sub</span> getDomains <span style="color: #009900;">&#123;</span>
    logOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Fetching db for domains...&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$result</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">selectall_hashref</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;SELECT domain_name FROM domains WHERE ip_address IS NULL&quot;</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">'domain_name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    logOut<span style="color: #009900;">&#40;</span><span style="color: #000066;">keys</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">%$result</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #ff0000;">&quot; domains returned.&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$updatedDomains</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$noIpDomains</span>    <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">foreach</span> <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$id</span> <span style="color: #009900;">&#40;</span><span style="color: #000066;">keys</span> <span style="color: #0000ff;">%$result</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$ip</span> <span style="color: #339933;">=</span> getIpAddress<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$id</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>domain_name<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$ip</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            logOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Ip found $ip for $result-&gt;{$id}-&gt;{domain_name}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">my</span> <span style="color: #339933;">@</span><span style="color: #000066;">values</span> <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$ip</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$result</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span><span style="color: #0000ff;">$id</span><span style="color: #009900;">&#125;</span><span style="color: #339933;">-&gt;</span><span style="color: #009900;">&#123;</span>domain_name<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$re</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$dbh</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">do</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;UPDATE domains SET ip_address=? WHERE domain_name=?&quot;</span><span style="color: #339933;">,</span><span style="color: #000066;">undef</span><span style="color: #339933;">,</span> <span style="color: #339933;">@</span><span style="color: #000066;">values</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
                <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$re</span> <span style="color: #339933;">==</span> 1<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
                    <span style="color: #0000ff;">$updatedDomains</span><span style="color: #339933;">++;</span>
                <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
            logOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;no ip for $result-&gt;{$id}-&gt;{domain_name}&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
            <span style="color: #0000ff;">$noIpDomains</span><span style="color: #339933;">++;</span>
        <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span>
    logOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Updated Domains: $updatedDomains&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    logOut<span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Domains with no Ip found: $noIpDomains&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#script starts here</span>
initialize<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
getDomains<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></pre><!--END_DEVFMTCODE--></p>
<p>Maybe there are more efficient methods but as I said, this worked pretty well, it didn&#8217;t consume a lot of results and it performs fast enough for my needs.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/development/bulk-domain-name-resolver-with-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Partial Db backups with mysqldump</title>
		<link>http://blog.ivanvillareal.info/development/partial-db-backups-with-mysqldump/</link>
		<comments>http://blog.ivanvillareal.info/development/partial-db-backups-with-mysqldump/#comments</comments>
		<pubDate>Wed, 05 May 2010 08:30:09 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Mysql]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=236</guid>
		<description><![CDATA[I was updating my db dev instance with a set of changes, and when I was restoring the dump for a table it contained a drop db clause   it was a simple table and it took a about 15 seconds to finish the operation, when I looked at the db schema all the [...]]]></description>
			<content:encoded><![CDATA[<p>I was updating my db dev instance with a set of changes, and when I was restoring the dump for a table it contained a drop db clause <img src='http://blog.ivanvillareal.info/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  it was a simple table and it took a about 15 seconds to finish the operation, when I looked at the db schema all the tables were gone!</p>
<p>This db has a very large table about 16Gb of binary data, so getting a new dump would require a lot of time, so as workaround I’ve dumped only sets of data that I need to my tests.</p>
<p>First I did a dump of the db schema with no data:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">mysqldump <span style="color: #660033;">-h</span> host-u <span style="color: #800000;">${USER}</span> <span style="color: #660033;">--password</span>=<span style="color: #800000;">${PASS}</span> <span style="color: #660033;">--no-data</span> <span style="color: #660033;">--add-drop-database</span> <span style="color: #660033;">--databases</span> largeDb<span style="color: #000000; font-weight: bold;">&gt;</span> schema_largeDb.sql</div></pre><!--END_DEVFMTCODE--></p>
<p>then I created a dump for the tables that I need, for this I have to include a list of tables that I don’t want, I’ve created the list of unwanted tables manually.</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">mysqldump <span style="color: #660033;">-h</span> host-u <span style="color: #800000;">${USER}</span> <span style="color: #660033;">--password</span>=<span style="color: #800000;">${PASS}</span> <span style="color: #660033;">--no-create-info</span> <span style="color: #660033;">--ignore-table</span>=largeDb.unwantedTable1 <span style="color: #660033;">--ignore-table</span>=largeDb.unwantedTable2 <span style="color: #660033;">--ignore-table</span>=largeDb.unwantedTable3 <span style="color: #000000; font-weight: bold;">&gt;</span> smallData.sql</div></pre><!--END_DEVFMTCODE--></p>
<p>And because I need data from the big table, I’ve used the –where clause to limit the rows returned in</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">mysqldump <span style="color: #660033;">-h</span> host-u <span style="color: #800000;">${USER}</span> <span style="color: #660033;">--password</span>=<span style="color: #800000;">${PASS}</span> <span style="color: #ff0000;">&quot;--where=brand_id='2496'&quot;</span> largeDb bigTable <span style="color: #000000; font-weight: bold;">&gt;</span> binaryData.sql</div></pre><!--END_DEVFMTCODE--></p>
<p>With this one I was able to get only the binaryData that I need to make my tests, instead of waiting to get for the entire dbDump,</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/development/partial-db-backups-with-mysqldump/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upgrading php5.1 to php5.3 on CENTOS 4</title>
		<link>http://blog.ivanvillareal.info/linux/upgrading-php5-1-to-php5-3-on-centos-4/</link>
		<comments>http://blog.ivanvillareal.info/linux/upgrading-php5-1-to-php5-3-on-centos-4/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 20:23:34 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[configuration]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=232</guid>
		<description><![CDATA[I've used the remi repo for quickly upgrade php to 5.3 and mysql to 5.1 on a Centos 4 server]]></description>
			<content:encoded><![CDATA[<p>I needed to update the php version of a centos 4 box, so this is what I did:</p>
<p>I&#8217;ve decided to go for the easy way, using the remi repo, so first I&#8217;ve Downloaded the Extra Packages for Enterprise Linux (<em style="font-weight: bold; font-style: normal;">EPEL</em>)</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>box php5.3<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># wget http://download.fedora.redhat.com/pub/epel/4/i386/epel-release-4-9.noarch.rpm</span>
--<span style="color: #000000;">13</span>:08:07--  http:<span style="color: #000000; font-weight: bold;">//</span>download.fedora.redhat.com<span style="color: #000000; font-weight: bold;">/</span>pub<span style="color: #000000; font-weight: bold;">/</span>epel<span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">4</span><span style="color: #000000; font-weight: bold;">/</span>i386<span style="color: #000000; font-weight: bold;">/</span>epel-release-<span style="color: #000000;">4</span>-9.noarch.rpm
           =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">`</span>epel-release-<span style="color: #000000;">4</span>-9.noarch.rpm<span style="color: #ff0000;">'</span>
<span style="color: #ff0000;">Resolving download.fedora.redhat.com... 209.132.183.67</span>
<span style="color: #ff0000;">Connecting to download.fedora.redhat.com|209.132.183.67|:80... connected.</span>
<span style="color: #ff0000;">HTTP request sent, awaiting response... 200 OK</span>
<span style="color: #ff0000;">Length: 13,686 (13K) [application/x-rpm]</span>
&nbsp;
<span style="color: #ff0000;">100%[=================================================================================&gt;] 13,686        --.--K/s            </span>
&nbsp;
<span style="color: #ff0000;">13:08:08 (405.60 KB/s) - `epel-release-4-9.noarch.rpm'</span> saved <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">13686</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">13686</span><span style="color: #7a0874; font-weight: bold;">&#93;</span></div></pre><!--END_DEVFMTCODE--></p>
<p>Then the remi repo:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>box php5.3<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># wget http://rpms.famillecollet.com/enterprise/remi-release-4.rpm</span>
--<span style="color: #000000;">13</span>:08:<span style="color: #000000;">21</span>--  http:<span style="color: #000000; font-weight: bold;">//</span>rpms.famillecollet.com<span style="color: #000000; font-weight: bold;">/</span>enterprise<span style="color: #000000; font-weight: bold;">/</span>remi-release-4.rpm
           =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">`</span>remi-release-4.rpm<span style="color: #ff0000;">'</span>
<span style="color: #ff0000;">Resolving rpms.famillecollet.com... 88.191.60.189</span>
<span style="color: #ff0000;">Connecting to rpms.famillecollet.com|88.191.60.189|:80... connected.</span>
<span style="color: #ff0000;">HTTP request sent, awaiting response... 200 OK</span>
<span style="color: #ff0000;">Length: 5,120 (5.0K) [application/x-rpm]</span>
&nbsp;
<span style="color: #ff0000;">100%[=================================================================================&gt;] 5,120         32.45K/s            </span>
&nbsp;
<span style="color: #ff0000;">13:08:22 (32.41 KB/s) - `remi-release-4.rpm'</span> saved <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">5120</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">5120</span><span style="color: #7a0874; font-weight: bold;">&#93;</span></div></pre><!--END_DEVFMTCODE--></p>
<p>Then I&#8217;ve upgraded both repos:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>box php5.3<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># rpm -Uvh remi-release-4*.rpm epel-release-4*.rpm</span>
warning: remi-release-4.rpm: V3 DSA signature: NOKEY, key ID 00f97f56
warning: epel-release-<span style="color: #000000;">4</span>-9.noarch.rpm: V3 DSA signature: NOKEY, key ID 217521f6
Preparing...                <span style="color: #666666; font-style: italic;">########################################### [100%]</span>
   <span style="color: #000000;">1</span>:epel-release           <span style="color: #666666; font-style: italic;">########################################### [ 50%]</span>
   <span style="color: #000000;">2</span>:remi-release           <span style="color: #666666; font-style: italic;">########################################### [100%]</span>
</div></pre><!--END_DEVFMTCODE--></p>
<p>and after that I downloaded the remi repo file for Yum:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>box php5.3<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># cd /etc/yum.repos.d/</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>box yum.repos.d<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># wget http://rpms.famillecollet.com/remi-enterprise.repo</span>
--<span style="color: #000000;">13</span>:09:<span style="color: #000000;">28</span>--  http:<span style="color: #000000; font-weight: bold;">//</span>rpms.famillecollet.com<span style="color: #000000; font-weight: bold;">/</span>remi-enterprise.repo
           =<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">`</span>remi-enterprise.repo<span style="color: #ff0000;">'</span>
<span style="color: #ff0000;">Resolving rpms.famillecollet.com... 88.191.60.189</span>
<span style="color: #ff0000;">Connecting to rpms.famillecollet.com|88.191.60.189|:80... connected.</span>
<span style="color: #ff0000;">HTTP request sent, awaiting response... 200 OK</span>
<span style="color: #ff0000;">Length: 793 [text/plain]</span>
&nbsp;
<span style="color: #ff0000;">100%[=================================================================================&gt;] 793           --.--K/s            </span>
&nbsp;
<span style="color: #ff0000;">13:09:28 (50.42 MB/s) - `remi-enterprise.repo'</span> saved <span style="color: #7a0874; font-weight: bold;">&#91;</span><span style="color: #000000;">793</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">793</span><span style="color: #7a0874; font-weight: bold;">&#93;</span></div></pre><!--END_DEVFMTCODE--></p>
<p>After that I just told yum to upgrade php:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>box yum.repos.d<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># yum --enable remi update php</span>
Repository remi is listed <span style="color: #c20cb9; font-weight: bold;">more</span> than once <span style="color: #000000; font-weight: bold;">in</span> the configuration
Repository remi-test is listed <span style="color: #c20cb9; font-weight: bold;">more</span> than once <span style="color: #000000; font-weight: bold;">in</span> the configuration
Setting up Update Process
Setting up repositories
epel                      100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> 3.4 kB    00:00    
remi                      100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> 2.6 kB    00:00    
Reading repository metadata <span style="color: #000000; font-weight: bold;">in</span> from <span style="color: #7a0874; font-weight: bold;">local</span> files
357f538e0bf37d10983cd3b22 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000;">732</span> kB    00:06    
epel      : <span style="color: #666666; font-style: italic;">################################################## 2267/2267</span>
e849a85ae6e8f1b8e5e71c08b 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000;">128</span> kB    00:03    
remi      : <span style="color: #666666; font-style: italic;">################################################## 444/444</span>
Resolving Dependencies
--<span style="color: #000000; font-weight: bold;">&gt;</span> Populating transaction <span style="color: #000000; font-weight: bold;">set</span> with selected packages. Please wait.
---<span style="color: #000000; font-weight: bold;">&gt;</span> Downloading header <span style="color: #000000; font-weight: bold;">for</span> php to pack into transaction set.
php-5.3.2-1.el4.remi.x86_ 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span>  19 kB    00:00    
---<span style="color: #000000; font-weight: bold;">&gt;</span> Package php.x86_64 0:5.3.2-1.el4.remi <span style="color: #000000; font-weight: bold;">set</span> to be updated
--<span style="color: #000000; font-weight: bold;">&gt;</span> Running transaction check
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: php-common = 5.3.2-1.el4.remi <span style="color: #000000; font-weight: bold;">for</span> package: php
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: php-cli = 5.3.2-1.el4.remi <span style="color: #000000; font-weight: bold;">for</span> package: php
--<span style="color: #000000; font-weight: bold;">&gt;</span> Restarting Dependency Resolution with new changes.
--<span style="color: #000000; font-weight: bold;">&gt;</span> Populating transaction <span style="color: #000000; font-weight: bold;">set</span> with selected packages. Please wait.
---<span style="color: #000000; font-weight: bold;">&gt;</span> Downloading header <span style="color: #000000; font-weight: bold;">for</span> php-common to pack into transaction set.
php-common-5.3.2-1.el4.re 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span>  25 kB    00:01    
---<span style="color: #000000; font-weight: bold;">&gt;</span> Package php-common.x86_64 0:5.3.2-1.el4.remi <span style="color: #000000; font-weight: bold;">set</span> to be updated
---<span style="color: #000000; font-weight: bold;">&gt;</span> Downloading header <span style="color: #000000; font-weight: bold;">for</span> php-cli to pack into transaction set.
php-cli-5.3.2-1.el4.remi. 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span>  19 kB    00:01    
---<span style="color: #000000; font-weight: bold;">&gt;</span> Package php-cli.x86_64 0:5.3.2-1.el4.remi <span style="color: #000000; font-weight: bold;">set</span> to be updated
--<span style="color: #000000; font-weight: bold;">&gt;</span> Running transaction check
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: php-common = 5.1.6-3.el4s1.10 <span style="color: #000000; font-weight: bold;">for</span> package: php-mysql
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: php-common = 5.1.6-3.el4s1.10 <span style="color: #000000; font-weight: bold;">for</span> package: php-xml
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: php-common = 5.1.6-3.el4s1.10 <span style="color: #000000; font-weight: bold;">for</span> package: php-pdo
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: libedit.so.0<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>64bit<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> package: php-cli
--<span style="color: #000000; font-weight: bold;">&gt;</span> Restarting Dependency Resolution with new changes.
--<span style="color: #000000; font-weight: bold;">&gt;</span> Populating transaction <span style="color: #000000; font-weight: bold;">set</span> with selected packages. Please wait.
---<span style="color: #000000; font-weight: bold;">&gt;</span> Downloading header <span style="color: #000000; font-weight: bold;">for</span> php-xml to pack into transaction set.
php-xml-5.3.2-1.el4.remi. 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span>  20 kB    00:00    
---<span style="color: #000000; font-weight: bold;">&gt;</span> Package php-xml.x86_64 0:5.3.2-1.el4.remi <span style="color: #000000; font-weight: bold;">set</span> to be updated
---<span style="color: #000000; font-weight: bold;">&gt;</span> Downloading header <span style="color: #000000; font-weight: bold;">for</span> libedit to pack into transaction set.
libedit-20090923-3.0_1.el 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> 5.8 kB    00:00    
---<span style="color: #000000; font-weight: bold;">&gt;</span> Package libedit.x86_64 0:20090923-3.0_1.el4.rf <span style="color: #000000; font-weight: bold;">set</span> to be updated
---<span style="color: #000000; font-weight: bold;">&gt;</span> Downloading header <span style="color: #000000; font-weight: bold;">for</span> php-pdo to pack into transaction set.
php-pdo-5.3.2-1.el4.remi. 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span>  19 kB    00:00    
---<span style="color: #000000; font-weight: bold;">&gt;</span> Package php-pdo.x86_64 0:5.3.2-1.el4.remi <span style="color: #000000; font-weight: bold;">set</span> to be updated
---<span style="color: #000000; font-weight: bold;">&gt;</span> Downloading header <span style="color: #000000; font-weight: bold;">for</span> php-mysql to pack into transaction set.
php-mysql-5.3.2-1.el4.rem 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span>  19 kB    00:00    
---<span style="color: #000000; font-weight: bold;">&gt;</span> Package php-mysql.x86_64 0:5.3.2-1.el4.remi <span style="color: #000000; font-weight: bold;">set</span> to be updated
--<span style="color: #000000; font-weight: bold;">&gt;</span> Running transaction check
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: libsqlite.so.0<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>64bit<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> package: php-pdo
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: libmysqlclient.so.16<span style="color: #7a0874; font-weight: bold;">&#40;</span>libmysqlclient_16<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>64bit<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> package: php-mysql
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: libmysqlclient.so.16<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>64bit<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> package: php-mysql
--<span style="color: #000000; font-weight: bold;">&gt;</span> Restarting Dependency Resolution with new changes.
--<span style="color: #000000; font-weight: bold;">&gt;</span> Populating transaction <span style="color: #000000; font-weight: bold;">set</span> with selected packages. Please wait.
---<span style="color: #000000; font-weight: bold;">&gt;</span> Downloading header <span style="color: #000000; font-weight: bold;">for</span> sqlite2 to pack into transaction set.
sqlite2-2.8.17-2.el4.remi 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> 5.2 kB    00:00    
---<span style="color: #000000; font-weight: bold;">&gt;</span> Package sqlite2.x86_64 0:2.8.17-2.el4.remi <span style="color: #000000; font-weight: bold;">set</span> to be updated
---<span style="color: #000000; font-weight: bold;">&gt;</span> Downloading header <span style="color: #000000; font-weight: bold;">for</span> mysql-libs to pack into transaction set.
mysql-libs-5.1.45-1.el4.r 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span>  24 kB    00:00    
---<span style="color: #000000; font-weight: bold;">&gt;</span> Package mysql-libs.x86_64 0:5.1.45-1.el4.remi <span style="color: #000000; font-weight: bold;">set</span> to be updated
--<span style="color: #000000; font-weight: bold;">&gt;</span> Running transaction check
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: libmysqlclient.so.15<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>64bit<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> package: perl-DBD-MySQL
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: libmysqlclient.so.15<span style="color: #7a0874; font-weight: bold;">&#40;</span>libmysqlclient_15<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>64bit<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> package: mysql-server
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: libmysqlclient_r.so.15<span style="color: #7a0874; font-weight: bold;">&#40;</span>libmysqlclient_15<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>64bit<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> package: mysql-server
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: libmysqlclient.so.15<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>64bit<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> package: mysql-server
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: libmysqlclient.so.15<span style="color: #7a0874; font-weight: bold;">&#40;</span>libmysqlclient_15<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>64bit<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> package: perl-DBD-MySQL
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: mysql-libs = 5.0.82sp1-1.el4_8 <span style="color: #000000; font-weight: bold;">for</span> package: mysql
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: libmysqlclient.so.15<span style="color: #7a0874; font-weight: bold;">&#40;</span>libmysqlclient_15<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>64bit<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> package: mysql
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: libmysqlclient.so.15<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>64bit<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> package: mysql
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: libmysqlclient_r.so.15<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>64bit<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> package: mysql-server
--<span style="color: #000000; font-weight: bold;">&gt;</span> Restarting Dependency Resolution with new changes.
--<span style="color: #000000; font-weight: bold;">&gt;</span> Populating transaction <span style="color: #000000; font-weight: bold;">set</span> with selected packages. Please wait.
---<span style="color: #000000; font-weight: bold;">&gt;</span> Downloading header <span style="color: #000000; font-weight: bold;">for</span> mysqlclient15 to pack into transaction set.
mysqlclient15-5.0.67-1.el 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> 3.9 kB    00:00    
---<span style="color: #000000; font-weight: bold;">&gt;</span> Package mysqlclient15.x86_64 0:5.0.67-1.el4.remi <span style="color: #000000; font-weight: bold;">set</span> to be updated
---<span style="color: #000000; font-weight: bold;">&gt;</span> Package perl-DBD-mysql.x86_64 0:4.013-1.el4.rf <span style="color: #000000; font-weight: bold;">set</span> to be updated
---<span style="color: #000000; font-weight: bold;">&gt;</span> Downloading header <span style="color: #000000; font-weight: bold;">for</span> mysql to pack into transaction set.
mysql-5.1.45-1.el4.remi.x 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span>  19 kB    00:00    
---<span style="color: #000000; font-weight: bold;">&gt;</span> Package mysql.x86_64 0:5.1.45-1.el4.remi <span style="color: #000000; font-weight: bold;">set</span> to be updated
---<span style="color: #000000; font-weight: bold;">&gt;</span> Downloading header <span style="color: #000000; font-weight: bold;">for</span> mysql-server to pack into transaction set.
mysql-server-5.1.45-1.el4 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span>  27 kB    00:00    
---<span style="color: #000000; font-weight: bold;">&gt;</span> Package mysql-server.x86_64 0:5.1.45-1.el4.remi <span style="color: #000000; font-weight: bold;">set</span> to be updated
--<span style="color: #000000; font-weight: bold;">&gt;</span> Running transaction check
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: libmysqlclient.so.14<span style="color: #7a0874; font-weight: bold;">&#40;</span>libmysqlclient_14<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>64bit<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> package: perl-DBD-mysql
--<span style="color: #000000; font-weight: bold;">&gt;</span> Processing Dependency: libmysqlclient.so.14<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#40;</span>64bit<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">for</span> package: perl-DBD-mysql
--<span style="color: #000000; font-weight: bold;">&gt;</span> Restarting Dependency Resolution with new changes.
--<span style="color: #000000; font-weight: bold;">&gt;</span> Populating transaction <span style="color: #000000; font-weight: bold;">set</span> with selected packages. Please wait.
---<span style="color: #000000; font-weight: bold;">&gt;</span> Downloading header <span style="color: #000000; font-weight: bold;">for</span> mysqlclient14 to pack into transaction set.
mysqlclient14-4.1.22-1.el 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> 5.5 kB    00:00    
---<span style="color: #000000; font-weight: bold;">&gt;</span> Package mysqlclient14.x86_64 0:4.1.22-1.el4.remi <span style="color: #000000; font-weight: bold;">set</span> to be updated
--<span style="color: #000000; font-weight: bold;">&gt;</span> Running transaction check
&nbsp;
Dependencies Resolved
&nbsp;
=============================================================================
Package                 Arch       Version          Repository        Size
=============================================================================
Installing:
perl-DBD-mysql          x86_64     4.013-1.el4.rf   rpmforge          228 k
     replacing  perl-DBD-MySQL.x86_64 4.008-1.el4s1
&nbsp;
Updating:
php                     x86_64     5.3.2-1.el4.remi  remi              1.4 M
Installing <span style="color: #000000; font-weight: bold;">for</span> dependencies:
libedit                 x86_64     20090923-3.0_1.el4.rf  rpmforge          265 k
mysqlclient14           x86_64     4.1.22-1.el4.remi  remi              1.2 M
mysqlclient15           x86_64     5.0.67-1.el4.remi  remi              1.3 M
sqlite2                 x86_64     2.8.17-2.el4.remi  remi              161 k
Updating <span style="color: #000000; font-weight: bold;">for</span> dependencies:
mysql                   x86_64     5.1.45-1.el4.remi  remi              1.0 M
mysql-libs              x86_64     5.1.45-1.el4.remi  remi              1.7 M
mysql-server            x86_64     5.1.45-1.el4.remi  remi               11 M
php-cli                 x86_64     5.3.2-1.el4.remi  remi              2.6 M
php-common              x86_64     5.3.2-1.el4.remi  remi              963 k
php-mysql               x86_64     5.3.2-1.el4.remi  remi              155 k
php-pdo                 x86_64     5.3.2-1.el4.remi  remi              177 k
php-xml                 x86_64     5.3.2-1.el4.remi  remi              232 k
&nbsp;
Transaction Summary
=============================================================================
Install      5 Package<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span>        
Update       9 Package<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span>        
Remove       0 Package<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span>        
Total download <span style="color: #c20cb9; font-weight: bold;">size</span>: 22 M
Is this ok <span style="color: #7a0874; font-weight: bold;">&#91;</span>y<span style="color: #000000; font-weight: bold;">/</span>N<span style="color: #7a0874; font-weight: bold;">&#93;</span>: y
Downloading Packages:
<span style="color: #7a0874; font-weight: bold;">&#40;</span>1<span style="color: #000000; font-weight: bold;">/</span>14<span style="color: #7a0874; font-weight: bold;">&#41;</span>: php-xml-5.3.2-1.e 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> 232 kB    00:04    
<span style="color: #7a0874; font-weight: bold;">&#40;</span>2<span style="color: #000000; font-weight: bold;">/</span>14<span style="color: #7a0874; font-weight: bold;">&#41;</span>: libedit-20090923- 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> 265 kB    00:04    
<span style="color: #7a0874; font-weight: bold;">&#40;</span>3<span style="color: #000000; font-weight: bold;">/</span>14<span style="color: #7a0874; font-weight: bold;">&#41;</span>: php-common-5.3.2- 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> 963 kB    00:15    
<span style="color: #7a0874; font-weight: bold;">&#40;</span>4<span style="color: #000000; font-weight: bold;">/</span>14<span style="color: #7a0874; font-weight: bold;">&#41;</span>: mysqlclient15-5.0 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> 1.3 MB    00:23    
<span style="color: #7a0874; font-weight: bold;">&#40;</span>5<span style="color: #000000; font-weight: bold;">/</span>14<span style="color: #7a0874; font-weight: bold;">&#41;</span>: php-cli-5.3.2-1.e 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> 2.6 MB    00:35    
<span style="color: #7a0874; font-weight: bold;">&#40;</span>6<span style="color: #000000; font-weight: bold;">/</span>14<span style="color: #7a0874; font-weight: bold;">&#41;</span>: perl-DBD-mysql-4. 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> 228 kB    00:04    
<span style="color: #7a0874; font-weight: bold;">&#40;</span>7<span style="color: #000000; font-weight: bold;">/</span>14<span style="color: #7a0874; font-weight: bold;">&#41;</span>: php-pdo-5.3.2-1.e 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> 177 kB    00:05    
<span style="color: #7a0874; font-weight: bold;">&#40;</span>8<span style="color: #000000; font-weight: bold;">/</span>14<span style="color: #7a0874; font-weight: bold;">&#41;</span>: mysql-5.1.45-1.el 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> 1.0 MB    00:15    
<span style="color: #7a0874; font-weight: bold;">&#40;</span>9<span style="color: #000000; font-weight: bold;">/</span>14<span style="color: #7a0874; font-weight: bold;">&#41;</span>: sqlite2-2.8.17-2. 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> 161 kB    00:05    
<span style="color: #7a0874; font-weight: bold;">&#40;</span>10<span style="color: #000000; font-weight: bold;">/</span>14<span style="color: #7a0874; font-weight: bold;">&#41;</span>: mysqlclient14-4. 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> 1.2 MB    00:15    
<span style="color: #7a0874; font-weight: bold;">&#40;</span>11<span style="color: #000000; font-weight: bold;">/</span>14<span style="color: #7a0874; font-weight: bold;">&#41;</span>: mysql-server-5.1 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span>  11 MB    01:59    
<span style="color: #7a0874; font-weight: bold;">&#40;</span>12<span style="color: #000000; font-weight: bold;">/</span>14<span style="color: #7a0874; font-weight: bold;">&#41;</span>: php-5.3.2-1.el4. 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> 1.4 MB    00:23    
<span style="color: #7a0874; font-weight: bold;">&#40;</span>13<span style="color: #000000; font-weight: bold;">/</span>14<span style="color: #7a0874; font-weight: bold;">&#41;</span>: mysql-libs-5.1.4 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> 1.7 MB    00:23    
<span style="color: #7a0874; font-weight: bold;">&#40;</span>14<span style="color: #000000; font-weight: bold;">/</span>14<span style="color: #7a0874; font-weight: bold;">&#41;</span>: php-mysql-5.3.2- 100<span style="color: #000000; font-weight: bold;">%</span> <span style="color: #000000; font-weight: bold;">|</span>=========================<span style="color: #000000; font-weight: bold;">|</span> 155 kB    00:04    
warning: rpmts_HdrFromFdno: V3 DSA signature: NOKEY, key ID 00f97f56
Public key <span style="color: #000000; font-weight: bold;">for</span> php-xml-5.3.2-1.el4.remi.x86_64.rpm is not installed
Retrieving GPG key from http:<span style="color: #000000; font-weight: bold;">//</span>rpms.famillecollet.com<span style="color: #000000; font-weight: bold;">/</span>RPM-GPG-KEY-remi
Importing GPG key 0x00F97F56 <span style="color: #ff0000;">&quot;Remi Collet &quot;</span>
Is this ok <span style="color: #7a0874; font-weight: bold;">&#91;</span>y<span style="color: #000000; font-weight: bold;">/</span>N<span style="color: #7a0874; font-weight: bold;">&#93;</span>:
&nbsp;
Key imported successfully
warning: only V3 signatures can be verified, skipping V4 signature
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
&nbsp;
WARNING : This php-<span style="color: #000000; font-weight: bold;">*</span> RPM are not official Fedora build and
overrides the official ones. Don<span style="color: #ff0000;">'t file bugs on Fedora Project.</span>
&nbsp;
<span style="color: #ff0000;">Use dedicated forums http://forums.famillecollet.com/</span>
&nbsp;
<span style="color: #ff0000;">  Updating  : php-common                                           [ 1/24]warning: /etc/php.ini created as /etc/php.ini.rpmnew</span>
<span style="color: #ff0000;">  Updating  : php-common                   ####################### [ 1/24]</span>
<span style="color: #ff0000;">  Installing: mysqlclient15                ####################### [ 2/24]</span>
<span style="color: #ff0000;">warning: only V3 signatures can be verified, skipping V4 signature</span>
&nbsp;
<span style="color: #ff0000;">WARNING : This MySQL RPM is not an official Fedora build and it</span>
<span style="color: #ff0000;">overrides the official one. Don'</span>t <span style="color: #c20cb9; font-weight: bold;">file</span> bugs on Fedora Project.
Use dedicated forums http:<span style="color: #000000; font-weight: bold;">//</span>forums.famillecollet.com<span style="color: #000000; font-weight: bold;">/</span>
&nbsp;
  Updating  : mysql-libs                                           <span style="color: #7a0874; font-weight: bold;">&#91;</span> 3<span style="color: #000000; font-weight: bold;">/</span>24<span style="color: #7a0874; font-weight: bold;">&#93;</span>warning: <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>my.cnf created <span style="color: #c20cb9; font-weight: bold;">as</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>my.cnf.rpmnew
  Updating  : mysql-libs                   <span style="color: #666666; font-style: italic;">####################### [ 3/24]</span>
  Updating  : mysql                        <span style="color: #666666; font-style: italic;">####################### [ 4/24]</span>
  Installing: mysqlclient14                <span style="color: #666666; font-style: italic;">####################### [ 5/24]</span>
  Installing: sqlite2                      <span style="color: #666666; font-style: italic;">####################### [ 6/24]</span>
  Updating  : php-pdo                      <span style="color: #666666; font-style: italic;">####################### [ 7/24]</span>
  Installing: libedit                      <span style="color: #666666; font-style: italic;">####################### [ 8/24]</span>
  Updating  : php-cli                      <span style="color: #666666; font-style: italic;">####################### [ 9/24]</span>
  Updating  : php                          <span style="color: #666666; font-style: italic;">####################### [10/24]</span>
  Updating  : php-mysql                    <span style="color: #666666; font-style: italic;">####################### [11/24]</span>
  Updating  : php-xml                      <span style="color: #666666; font-style: italic;">####################### [12/24]</span>
  Installing: perl-DBD-mysql               <span style="color: #666666; font-style: italic;">####################### [13/24]</span>
  Updating  : mysql-server                 <span style="color: #666666; font-style: italic;">####################### [14/24]</span>
  Cleanup   : php-xml                      <span style="color: #666666; font-style: italic;">####################### [15/24]</span>
  Cleanup   : php-common                   <span style="color: #666666; font-style: italic;">####################### [16/24]</span>
  Cleanup   : php-cli                      <span style="color: #666666; font-style: italic;">####################### [17/24]</span>
  Removing  : perl-DBD-MySQL               <span style="color: #666666; font-style: italic;">####################### [18/24]</span>
  Cleanup   : php-pdo                      <span style="color: #666666; font-style: italic;">####################### [19/24]</span>
  Cleanup   : mysql                        <span style="color: #666666; font-style: italic;">####################### [20/24]</span>
  Cleanup   : mysql-server                 <span style="color: #666666; font-style: italic;">####################### [21/24]</span>
  Cleanup   : php                          <span style="color: #666666; font-style: italic;">####################### [22/24]</span>
  Cleanup   : mysql-libs                   <span style="color: #666666; font-style: italic;">####################### [23/24]</span>
  Cleanup   : php-mysql                    <span style="color: #666666; font-style: italic;">####################### [24/24]</span>
&nbsp;
Installed: perl-DBD-mysql.x86_64 <span style="color: #000000;">0</span>:<span style="color: #000000;">4.013</span>-1.el4.rf
Dependency Installed: libedit.x86_64 <span style="color: #000000;">0</span>:<span style="color: #000000;">20090923</span>-<span style="color: #000000;">3.0</span>_1.el4.rf mysqlclient14.x86_64 <span style="color: #000000;">0</span>:4.1.22-1.el4.remi mysqlclient15.x86_64 <span style="color: #000000;">0</span>:5.0.67-1.el4.remi sqlite2.x86_64 <span style="color: #000000;">0</span>:2.8.17-2.el4.remi
Updated: php.x86_64 <span style="color: #000000;">0</span>:5.3.2-1.el4.remi
Dependency Updated: mysql.x86_64 <span style="color: #000000;">0</span>:5.1.45-1.el4.remi mysql-libs.x86_64 <span style="color: #000000;">0</span>:5.1.45-1.el4.remi mysql-server.x86_64 <span style="color: #000000;">0</span>:5.1.45-1.el4.remi php-cli.x86_64 <span style="color: #000000;">0</span>:5.3.2-1.el4.remi php-common.x86_64 <span style="color: #000000;">0</span>:5.3.2-1.el4.remi php-mysql.x86_64 <span style="color: #000000;">0</span>:5.3.2-1.el4.remi php-pdo.x86_64 <span style="color: #000000;">0</span>:5.3.2-1.el4.remi php-xml.x86_64 <span style="color: #000000;">0</span>:5.3.2-1.el4.remi
Replaced: perl-DBD-MySQL.x86_64 <span style="color: #000000;">0</span>:<span style="color: #000000;">4.008</span>-1.el4s1
Complete<span style="color: #000000; font-weight: bold;">!</span>
</div></pre><!--END_DEVFMTCODE--></p>
<p>When this was done, I just synced /etc/php.ini with the new one /etc/php.ini.rpmnew and /etc/my.cnf with /etc/my.cnf.rpmnew when this was done I just restarted mysql and apache and I php5.3 was now available.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/linux/upgrading-php5-1-to-php5-3-on-centos-4/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>GPS tracking fleet project (part. 1)</title>
		<link>http://blog.ivanvillareal.info/articles/gps-tracking-fleet-project-part-1/</link>
		<comments>http://blog.ivanvillareal.info/articles/gps-tracking-fleet-project-part-1/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 02:59:24 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=213</guid>
		<description><![CDATA[About a year ago I was talking to a friend that was working for a company that offered a fleet tracking service, he described the process and I just got curious about how could I implement the entire system easily, I did some research and there wasn’t a lot of information about the entire picture, [...]]]></description>
			<content:encoded><![CDATA[<p>About a year ago I was talking to a friend that was working for a company that offered a fleet tracking service, he described the process and I just got curious about how could I implement the entire system easily, I did some research and there wasn’t a lot of information about the entire picture, there were bits here and there but nothing concrete.</p>
<p>After a couple of days of researching I came up with a Plan to write a platform in one month in my spare time, the intention was to create a fully functional backend and front end pieces, with the ability to track any number of units.</p>
<p>It was a bit challenging because :</p>
<ol>
<li>The short time span I wanted to have this ready.</li>
<li>I didn’t have any hardware to test&nbsp; (GPS receivers, GPRS modems, or even a dedicated server to put the backend), and I didn’t want to spent any money buying any of this.</li>
<li>I didn’t had a lot of experience with Google maps <a href="http://code.google.com/apis/maps/" target="_blank">API</a>.</li>
</ol>
<p>The first thing I did was a diagram of how the system should work:</p>
<p><a href="http://blog.ivanvillareal.info/wp-content/uploads/2010/02/gpsplatformdiagram.png"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="gps-platform-diagram" src="http://blog.ivanvillareal.info/wp-content/uploads/2010/02/gpsplatformdiagram_thumb.png" border="0" alt="gps-platform-diagram" width="660" height="500" /></a></p>
<p>I’m not good with drawings so bear with me, let me explain the diagram:</p>
<p>There will be a tracking device in every truck that will be sending periodic updates about its&nbsp; location, speed, and other events trough a GPRS link, provided by a conventional GSM network, the device must be programmed to send this updates to a certain ip address (Application server), at specified periods of time.</p>
<p>The application server (background process) will have a daemon running on a specific port waiting for requests from tracking devices, if the tracking device is authorized it will accept the stream and save the info received from the device to a db.</p>
<p>The requirements for the backend application were:</p>
<ul>
<li>It should be able to run on Linux.</li>
<li>The process should be able to handle a large number of  requests.</li>
<li>It needed to be run as a daemon, interfacing with a system to logger.</li>
<li>It must be able to decode NMEA sentences and save them in a MySQL Db.</li>
</ul>
<p>The front end application, requirements were:</p>
<ul>
<li>Handle user authentication.</li>
<li>Present the gathered data in real time.</li>
<li>Generate reports.</li>
</ul>
<h3>Technology selection:</h3>
<p>With basic requirements on hand, the next thing was to look the technologies I should be using and this were my choices:</p>
<p>For the backend:</p>
<ul>
<li>Gentoo Linux</li>
<li>Java 1.6</li>
<li>Mysql 5.0</li>
</ul>
<p>For the frontend:</p>
<ul>
<li>Gentoo Linux</li>
<li>PHP 5.2</li>
<li>Jquery 1.3</li>
<li>Mysql 5.0</li>
</ul>
<p>In my next post I will describe the approach I took on the back end process and how I started building it.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/articles/gps-tracking-fleet-project-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP cross domain ajax Proxy</title>
		<link>http://blog.ivanvillareal.info/development/php-development/php-cross-domain-ajax-proxy/</link>
		<comments>http://blog.ivanvillareal.info/development/php-development/php-cross-domain-ajax-proxy/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 23:52:04 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cross site]]></category>
		<category><![CDATA[json]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[proxy]]></category>
		<category><![CDATA[stream_context_create]]></category>
		<category><![CDATA[webservice]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=224</guid>
		<description><![CDATA[In this post, I describe an easy way to create a json php proxy to call a remote webservice, and allow cross-site calls.]]></description>
			<content:encoded><![CDATA[<p>I received a javascript application, that made cross domain calls to a webservice using the <a href="http://flxhr.flensed.com/" target="_blank">flensed</a> library, this was pretty neat, but filling the dropdown boxes was very slow. Not to mention unnecessary, because I was going to embed the dropdown values into this modal window.</p>
<p>What I did was to refactor the javascript app, into php code to fill the values, and left the important webservice requests alone, I didn’t want to use the flXHR library, because the widget was so simple, so what I did was a php json-rpc proxy client, winch its work would be to post the data received from the client to a remote webservice.</p>
<p>I’m using Zend_Json to encode/decode json, because the php version on production is 5.1, and the php json extensions are not available.</p>
<p>First I create an object that will hold the data to be sent.</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="PHP"><div class="devcodeoverflow"><ol><li><span style="color: #000088;">$re</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> stdClass<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li><span style="color: #000088;">$re</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">brand_id</span>&nbsp;&nbsp;<span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'brand_id'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></li><li><span style="color: #000088;">$names</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'domains'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></li><li>&nbsp;</li><li><span style="color: #000088;">$domains</span> <span style="color: #339933;">=</span> <span style="color: #990000;">explode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;,&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$names</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li><span style="color: #000088;">$filteredDomains</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li><span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$domains</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$domain</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li> <span style="color: #000088;">$domainParts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">parse_url</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$domain</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$domainParts</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'host'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$domainParts</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'host'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li> <span style="color: #000088;">$filteredDomains</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$domainParts</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'host'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span></li><li> <span style="color: #009900;">&#125;</span></li><li><span style="color: #009900;">&#125;</span></li><li><span style="color: #000088;">$re</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">domains</span>&nbsp;&nbsp; <span style="color: #339933;">=</span> <span style="color: #000088;">$filteredDomains</span><span style="color: #339933;">;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>That was simple, I didn&#8217;t have to worry about filtering the user input, because the webservice will take care of that, the only thing I do, is&nbsp; create an array of domains, with has only the host part.</p>
<p>after I have my Object ready I encode it as a json string, open a socket and make the request, here is how I did it:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="PHP"><div class="devcodeoverflow"><ol><li><span style="color: #000088;">$request</span> <span style="color: #339933;">=</span> Zend_Json<span style="color: #339933;">::</span><span style="color: #004000;">encode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$re</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li><span style="color: #000088;">$opts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">'method'</span>&nbsp;&nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'POST'</span><span style="color: #339933;">,</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">'header'</span>&nbsp;&nbsp;<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Content-type: application/json'</span><span style="color: #339933;">,</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #0000ff;">'content'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$request</span></li><li>&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li><span style="color: #000088;">$context</span>&nbsp;&nbsp;<span style="color: #339933;">=</span> <span style="color: #990000;">stream_context_create</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$opts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li><span style="color: #000088;">$conection</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'r'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #000088;">$context</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li><li><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$conection</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li> <span style="color: #000088;">$reply</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span></li><li> <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span></li><li> <span style="color: #000088;">$reply</span><span style="color: #339933;">.=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$row</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></li><li><span style="color: #009900;">&#125;</span></li><li><span style="color: #000088;">$reply</span> <span style="color: #339933;">=</span> Zend_Json<span style="color: #339933;">::</span><span style="color: #004000;">decode</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$reply</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></li></ol></div></pre><!--END_DEVFMTCODE--></p>
<p>Pretty simple no?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/development/php-development/php-cross-domain-ajax-proxy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting first and last row from a group set without sub queries in mysql</title>
		<link>http://blog.ivanvillareal.info/development/mysql-development/getting-first-and-last-row-from-a-group-set-without-sub-queries-in-mysql/</link>
		<comments>http://blog.ivanvillareal.info/development/mysql-development/getting-first-and-last-row-from-a-group-set-without-sub-queries-in-mysql/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 01:45:24 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Mysql]]></category>
		<category><![CDATA[db]]></category>
		<category><![CDATA[group]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=206</guid>
		<description><![CDATA[How I use group_concat to get the last row from a GROUP_BY clause]]></description>
			<content:encoded><![CDATA[<p>When I use the GROUP BY clause in mysql It starts grouping by the first different row in the resultset so for example if I have this table:</p>
<p>&nbsp;</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="MySQL"><div class="devcodeoverflow">mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">select</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">from</span> grouptest<span style="color: #000033;">;</span>
<span style="color: #CC0099;">+----+---------+-------+------------+</span>
<span style="color: #CC0099;">|</span> id <span style="color: #CC0099;">|</span> city    <span style="color: #CC0099;">|</span> <span style="color: #990099; font-weight: bold;">value</span> <span style="color: #CC0099;">|</span> <span style="color: #999900; font-weight: bold;">date</span>       <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+----+---------+-------+------------+</span>
<span style="color: #CC0099;">|</span>  1 <span style="color: #CC0099;">|</span> tijuana <span style="color: #CC0099;">|</span>    10 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>02 <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span>  2 <span style="color: #CC0099;">|</span> tijuana <span style="color: #CC0099;">|</span>    11 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>09 <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span>  3 <span style="color: #CC0099;">|</span> tijuana <span style="color: #CC0099;">|</span>    15 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>12 <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span>  4 <span style="color: #CC0099;">|</span> tijuana <span style="color: #CC0099;">|</span>    17 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>17 <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span>  5 <span style="color: #CC0099;">|</span> tecate  <span style="color: #CC0099;">|</span>    12 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>10 <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span>  6 <span style="color: #CC0099;">|</span> tecate  <span style="color: #CC0099;">|</span>     1 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>14 <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span>  7 <span style="color: #CC0099;">|</span> tecate  <span style="color: #CC0099;">|</span>    29 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>17 <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">+----+---------+-------+------------+</span>
7 rows <span style="color: #990099; font-weight: bold;">in</span> <span style="color: #990099; font-weight: bold;">set</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.00</span> sec<span style="color: #FF00FF;">&#41;</span></div></pre><!--END_DEVFMTCODE--></p>
<p>&nbsp;</p>
<p>If I group by city this is what I get:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="MySQL"><div class="devcodeoverflow">mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> grouptest g <span style="color: #990099; font-weight: bold;">GROUP BY</span> city<span style="color: #000033;">;</span>
<span style="color: #CC0099;">+----+---------+-------+------------+</span>
<span style="color: #CC0099;">|</span> id <span style="color: #CC0099;">|</span> city    <span style="color: #CC0099;">|</span> <span style="color: #990099; font-weight: bold;">value</span> <span style="color: #CC0099;">|</span> <span style="color: #999900; font-weight: bold;">date</span>       <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+----+---------+-------+------------+</span>
<span style="color: #CC0099;">|</span>  5 <span style="color: #CC0099;">|</span> tecate  <span style="color: #CC0099;">|</span>    12 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>10 <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span>  1 <span style="color: #CC0099;">|</span> tijuana <span style="color: #CC0099;">|</span>    10 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>02 <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">+----+---------+-------+------------+</span>
2 rows <span style="color: #990099; font-weight: bold;">in</span> <span style="color: #990099; font-weight: bold;">set</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.00</span> sec<span style="color: #FF00FF;">&#41;</span></div></pre><!--END_DEVFMTCODE--></p>
<p>&nbsp;</p>
<p>But I want to get the last inserted rows, so could do a sub query like this:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="MySQL"><div class="devcodeoverflow">mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">FROM</span> grouptest g
    <span style="color: #CC0099;">-&gt;</span> <span style="color: #990099; font-weight: bold;">WHERE</span> g.<span style="color: #999900; font-weight: bold;">date</span> <span style="color: #CC0099;">=</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #990099; font-weight: bold;">SELECT</span> <span style="color: #000099;">MAX</span><span style="color: #FF00FF;">&#40;</span><span style="color: #999900; font-weight: bold;">date</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">FROM</span> grouptest gt <span style="color: #990099; font-weight: bold;">WHERE</span> g.city <span style="color: #CC0099;">=</span> gt.city<span style="color: #FF00FF;">&#41;</span>
    <span style="color: #CC0099;">-&gt;</span> <span style="color: #990099; font-weight: bold;">GROUP BY</span> g.city<span style="color: #000033;">;</span>
<span style="color: #CC0099;">+----+---------+-------+------------+</span>
<span style="color: #CC0099;">|</span> id <span style="color: #CC0099;">|</span> city    <span style="color: #CC0099;">|</span> <span style="color: #990099; font-weight: bold;">value</span> <span style="color: #CC0099;">|</span> <span style="color: #999900; font-weight: bold;">date</span>       <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+----+---------+-------+------------+</span>
<span style="color: #CC0099;">|</span>  7 <span style="color: #CC0099;">|</span> tecate  <span style="color: #CC0099;">|</span>    29 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>17 <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span>  4 <span style="color: #CC0099;">|</span> tijuana <span style="color: #CC0099;">|</span>    17 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>17 <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">+----+---------+-------+------------+</span>
2 rows <span style="color: #990099; font-weight: bold;">in</span> <span style="color: #990099; font-weight: bold;">set</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.00</span> sec<span style="color: #FF00FF;">&#41;</span></div></pre><!--END_DEVFMTCODE--></p>
<p>&nbsp;</p>
<p>But if the db is large making subqueries could be expensive, so a cleaner solution might be using the <a href="http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#function_group-concat" target="_blank">GROUP_CONCAT</a> function, so for example the above query could be written like this:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="MySQL"><div class="devcodeoverflow">mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">SELECT</span> id<span style="color: #000033;">,</span> city<span style="color: #000033;">,</span> <span style="color: #990099; font-weight: bold;">value</span><span style="color: #000033;">,</span> <span style="color: #999900; font-weight: bold;">date</span><span style="color: #000033;">,</span> <span style="color: #000099;">GROUP_CONCAT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #999900; font-weight: bold;">date</span><span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> all_dates
    <span style="color: #CC0099;">-&gt;</span> <span style="color: #990099; font-weight: bold;">FROM</span> grouptest g
    <span style="color: #CC0099;">-&gt;</span> <span style="color: #990099; font-weight: bold;">GROUP BY</span> city<span style="color: #000033;">;</span>
<span style="color: #CC0099;">+----+---------+-------+------------+---------------------------------------------+</span>
<span style="color: #CC0099;">|</span> id <span style="color: #CC0099;">|</span> city    <span style="color: #CC0099;">|</span> <span style="color: #990099; font-weight: bold;">value</span> <span style="color: #CC0099;">|</span> <span style="color: #999900; font-weight: bold;">date</span>       <span style="color: #CC0099;">|</span> all_dates                                   <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+----+---------+-------+------------+---------------------------------------------+</span>
<span style="color: #CC0099;">|</span>  5 <span style="color: #CC0099;">|</span> tecate  <span style="color: #CC0099;">|</span>    12 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>10 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>10<span style="color: #000033;">,</span>2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>14<span style="color: #000033;">,</span>2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>17            <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span>  1 <span style="color: #CC0099;">|</span> tijuana <span style="color: #CC0099;">|</span>    10 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>02 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>02<span style="color: #000033;">,</span>2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>09<span style="color: #000033;">,</span>2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>12<span style="color: #000033;">,</span>2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>17 <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">+----+---------+-------+------------+---------------------------------------------+</span>
2 rows <span style="color: #990099; font-weight: bold;">in</span> <span style="color: #990099; font-weight: bold;">set</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.00</span> sec<span style="color: #FF00FF;">&#41;</span></div></pre><!--END_DEVFMTCODE--><br />
&nbsp;<br />
At this point I can explode the all_dates column in php or split them in perl to get the last date for each city, but a little more work on our query could do our job simpler, something like this for instance:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="MySQL"><div class="devcodeoverflow">mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">SELECT</span> id<span style="color: #000033;">,</span> city<span style="color: #000033;">,</span> <span style="color: #990099; font-weight: bold;">value</span><span style="color: #000033;">,</span> <span style="color: #000099;">SUBSTRING_INDEX</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">GROUP_CONCAT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #999900; font-weight: bold;">date</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span><span style="color: #008000;">','</span><span style="color: #000033;">,</span><span style="color: #CC0099;">-</span>1<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> <span style="color: #999900; font-weight: bold;">date</span>
    <span style="color: #CC0099;">-&gt;</span> <span style="color: #990099; font-weight: bold;">FROM</span> grouptest g
    <span style="color: #CC0099;">-&gt;</span> <span style="color: #990099; font-weight: bold;">GROUP BY</span> city<span style="color: #000033;">;</span>
<span style="color: #CC0099;">+----+---------+-------+------------+</span>
<span style="color: #CC0099;">|</span> id <span style="color: #CC0099;">|</span> city    <span style="color: #CC0099;">|</span> <span style="color: #990099; font-weight: bold;">value</span> <span style="color: #CC0099;">|</span> <span style="color: #999900; font-weight: bold;">date</span>       <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+----+---------+-------+------------+</span>
<span style="color: #CC0099;">|</span>  5 <span style="color: #CC0099;">|</span> tecate  <span style="color: #CC0099;">|</span>    12 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>17 <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span>  1 <span style="color: #CC0099;">|</span> tijuana <span style="color: #CC0099;">|</span>    10 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>17 <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">+----+---------+-------+------------+</span>
2 rows <span style="color: #990099; font-weight: bold;">in</span> <span style="color: #990099; font-weight: bold;">set</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.00</span> sec<span style="color: #FF00FF;">&#41;</span>
</div></pre><!--END_DEVFMTCODE--><br />
&nbsp;<br />
Or if I need to get the first and last rows for each group set I just add the date column like this:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="MySQL"><div class="devcodeoverflow">mysql<span style="color: #CC0099;">&gt;</span> <span style="color: #990099; font-weight: bold;">SELECT</span> id<span style="color: #000033;">,</span> city<span style="color: #000033;">,</span> <span style="color: #990099; font-weight: bold;">value</span><span style="color: #000033;">,</span> <span style="color: #999900; font-weight: bold;">date</span> <span style="color: #990099; font-weight: bold;">as</span> first_date<span style="color: #000033;">,</span> <span style="color: #000099;">SUBSTRING_INDEX</span><span style="color: #FF00FF;">&#40;</span><span style="color: #000099;">GROUP_CONCAT</span><span style="color: #FF00FF;">&#40;</span><span style="color: #999900; font-weight: bold;">date</span><span style="color: #FF00FF;">&#41;</span><span style="color: #000033;">,</span><span style="color: #008000;">','</span><span style="color: #000033;">,</span><span style="color: #CC0099;">-</span>1<span style="color: #FF00FF;">&#41;</span> <span style="color: #990099; font-weight: bold;">AS</span> last_date
    <span style="color: #CC0099;">-&gt;</span> <span style="color: #990099; font-weight: bold;">FROM</span> grouptest g
    <span style="color: #CC0099;">-&gt;</span> <span style="color: #990099; font-weight: bold;">GROUP BY</span> city<span style="color: #000033;">;</span>
<span style="color: #CC0099;">+----+---------+-------+------------+------------+</span>
<span style="color: #CC0099;">|</span> id <span style="color: #CC0099;">|</span> city    <span style="color: #CC0099;">|</span> <span style="color: #990099; font-weight: bold;">value</span> <span style="color: #CC0099;">|</span> first_date <span style="color: #CC0099;">|</span> last_date  <span style="color: #CC0099;">|</span>
<span style="color: #CC0099;">+----+---------+-------+------------+------------+</span>
<span style="color: #CC0099;">|</span>  5 <span style="color: #CC0099;">|</span> tecate  <span style="color: #CC0099;">|</span>    12 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>10 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>17 <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">|</span>  1 <span style="color: #CC0099;">|</span> tijuana <span style="color: #CC0099;">|</span>    10 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>02 <span style="color: #CC0099;">|</span> 2010<span style="color: #CC0099;">-</span>02<span style="color: #CC0099;">-</span>17 <span style="color: #CC0099;">|</span> 
<span style="color: #CC0099;">+----+---------+-------+------------+------------+</span>
2 rows <span style="color: #990099; font-weight: bold;">in</span> <span style="color: #990099; font-weight: bold;">set</span> <span style="color: #FF00FF;">&#40;</span><span style="color: #008080;">0.00</span> sec<span style="color: #FF00FF;">&#41;</span>
</div></pre><!--END_DEVFMTCODE--></p>
<p>&nbsp;</p>
<p>There may be several other ways around this, but for now this approach is enough, I’m not sure about the impact this 2 functions may have on the server but I’m sure it is less than executing a subquery.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/development/mysql-development/getting-first-and-last-row-from-a-group-set-without-sub-queries-in-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compressing/Decompressing mysql dumps on the fly</title>
		<link>http://blog.ivanvillareal.info/linux/compressingdecompressing-mysql-dumps-on-the-fly/</link>
		<comments>http://blog.ivanvillareal.info/linux/compressingdecompressing-mysql-dumps-on-the-fly/#comments</comments>
		<pubDate>Wed, 17 Feb 2010 20:17:06 +0000</pubDate>
		<dc:creator>Ivan Villareal</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[pipes]]></category>
		<category><![CDATA[restore]]></category>

		<guid isPermaLink="false">http://blog.ivanvillareal.info/?p=197</guid>
		<description><![CDATA[One line commands I use to compress or decompress mysql dumps.]]></description>
			<content:encoded><![CDATA[<p>Using pipes and redirection in the shell we can do backups or restore them, performing compression or decompression on the fly, this are the commands I frequently use:</p>
<p>Create a backup <dbname>with mysqldump and compress the stream with bzip2<br />
<!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">ivan<span style="color: #000000; font-weight: bold;">@</span>mini:~$ mysqldump –h dbHost –u dbUser –pdbPass –add-drop-database –databases <span style="color: #000000; font-weight: bold;">&lt;</span>dbname<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">bzip2</span> <span style="color: #000000; font-weight: bold;">&gt;</span> dbName-02-<span style="color: #000000;">17</span>-2010.sql.bz2<span style="color: #000000; font-weight: bold;">&lt;/</span>dbname<span style="color: #000000; font-weight: bold;">&gt;</span></div></pre><!--END_DEVFMTCODE--></dbname></p>
<p>If I want to restore the backup I use:</p>
<p><!--DEVFMTCODE--><pre class="devcodeblock" title="Bash"><div class="devcodeoverflow">ivan<span style="color: #000000; font-weight: bold;">@</span>mini:~$ <span style="color: #c20cb9; font-weight: bold;">bunzip2</span> <span style="color: #000000; font-weight: bold;">&lt;</span> dbName-02-17-2010.sql.bz2 <span style="color: #000000; font-weight: bold;">|</span> mysql –h dbHost –u dbUser –pdbPass</div></pre><!--END_DEVFMTCODE--></p>
<p>I can switch bzip2 compression by changing only the program name for example gzip/gunzip lzma/unlzma</code></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.ivanvillareal.info/linux/compressingdecompressing-mysql-dumps-on-the-fly/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->
