<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[Thijs Lensselink's Blog]]></title>
  <link href="http://lenss.nl/atom.xml" rel="self"/>
  <link href="http://lenss.nl/"/>
  <updated>2014-01-27T08:13:44+01:00</updated>
  <id>http://lenss.nl/</id>
  <author>
    <name><![CDATA[Thijs Lensselink]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Get the first weekday of the month in PHP]]></title>
    <link href="http://lenss.nl/2013/11/first-weekday-of-month-in-php/"/>
    <updated>2013-11-15T11:05:53+01:00</updated>
    <id>http://lenss.nl/2013/11/first-weekday-of-month-in-php</id>
    <content type="html"><![CDATA[<p>A simple method to return the first weekdsay of a given month and year</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>getFirstWeekdayInMonth </span></figcaption>
 <div class="CodeRay">
  <div class="code"><pre>
<span class="keyword">private</span> <span class="keyword">function</span> <span class="function">_getFirstWeekdayInMonth</span>(<span class="local-variable">$month</span>, <span class="local-variable">$year</span>, <span class="local-variable">$day</span> = <span class="integer">1</span>) 
{
    <span class="local-variable">$dateData</span> = <span class="predefined">getdate</span>(<span class="predefined">mktime</span>(<span class="predefined-constant">null</span>, <span class="predefined-constant">null</span>, <span class="predefined-constant">null</span>, <span class="local-variable">$month</span>, <span class="local-variable">$day</span>, <span class="local-variable">$year</span>));
    <span class="keyword">if</span> (<span class="predefined">in_array</span>(<span class="local-variable">$dateData</span>[<span class="string"><span class="delimiter">'</span><span class="content">wday</span><span class="delimiter">'</span></span>], <span class="predefined">range</span>(<span class="integer">1</span>, <span class="integer">5</span>))) {
        <span class="keyword">return</span> <span class="local-variable">$dateData</span>[<span class="string"><span class="delimiter">'</span><span class="content">mday</span><span class="delimiter">'</span></span>];
    }
    <span class="keyword">return</span> <span class="local-variable">$this</span>-&gt;_getFirstWeekdayInMonth(<span class="local-variable">$month</span>, <span class="local-variable">$year</span>, (<span class="local-variable">$day</span>+<span class="integer">1</span>));
}

<span class="local-variable">$wday</span> = <span class="local-variable">$this</span>-&gt;_getFirstWeekdayInMonth(<span class="integer">11</span>, <span class="integer">2013</span>);
</pre></div>
</div>
 </figure></notextile></div>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Renaming a folder in git that contains submodules]]></title>
    <link href="http://lenss.nl/2013/10/git-move-folder-containing-submodules/"/>
    <updated>2013-10-23T13:05:12+02:00</updated>
    <id>http://lenss.nl/2013/10/git-move-folder-containing-submodules</id>
    <content type="html"><![CDATA[<p>Because of some project structure changes. It was required to renamed some folders. In git this should be as easy as running <strong>git mv</strong>. But when the folders you are trying to move contain submodules. Its a whole different story.</p>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
$ git mv old/ new
</pre></div>
</div>
 </figure></notextile></div>

<blockquote><p>fatal: source directory is empty, source=old/cookbooks/apache2, destination=new/cookbooks/apache2</p></blockquote>

<p>Like i said. This seems to work for normal folders. But submodules are a bit more complicated because of paths set in various files. So let’s try just moving them on the filesystem.</p>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
$ mv old/ new
$ git status
</pre></div>
</div>
 </figure></notextile></div>

<blockquote><p>#	deleted:    old/VVagrantfile.example<br />#	deleted:    old/cookbooks/apache2<br />#	deleted:    old/cookbooks/apt<br />#	deleted:    old/cookbooks/beanstalkd/.travis.yml</p></blockquote>

<p>That’s not what we’re looking for. We want to move the files. Not remove them. At this point i was at a loss and spend some time looking around <a href="http://stackoverflow.com/">stackoverflow</a>. Which has multiple solutions available from other developers. But none seemed to fit the bill. So i ended up combining a couple.</p>

<p>First create the new location and add it to the git index.</p>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
$ mkdir new
$ git add new
</pre></div>
</div>
 </figure></notextile></div>

<p>In my case i had normal folders and submodules in the same directory. So first i moved the normal folders to the new structure.</p>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
$ git mv old/[some folder] /new
</pre></div>
</div>
 </figure></notextile></div>

<p>Now it’s time for the submodules. We need to update the paths in each submodule’s <strong>.git</strong> file. And the paths in project <strong>.gitmodule</strong> file</p>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
$ find . -name .git -type f -print0 -type f | xargs -0 sed -i 's|old|new|g'
$ find . -name .gitmodule -type f -print0 -type f | xargs -0 sed -i 's|old|new|g'
</pre></div>
</div>
 </figure></notextile></div>

<p>After that add the <strong>.gitmodule</strong> file to the git index and checkout the status</p>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
$ git add .gitmodule
$ git status 
</pre></div>
</div>
 </figure></notextile></div>

<blockquote><p>fatal: Could not chdir to &#8216;../../../../../new/cookbooks/apache2&#8217;: No such file or directory<br />fatal: &#8216;git status &#8211;porcelain&#8217; failed in submodule old/cookbooks/apache2</p></blockquote>

<p>So we’re not there yet. As it turns out the git config file also contains the submodule paths. And the <strong>.git/modules</strong> folder contains a submodule mapping as well. So let’s fix that</p>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
$ find . -name config -print0 -type f | xargs -0 sed -i 's|old|new|g'
$ mv .git/modules/old .git/modules/new
$ git status
</pre></div>
</div>
 </figure></notextile></div>

<p>That looks good</p>

<blockquote><p>modified:   .gitmodules<br />#	renamed:    old/Vagrantfile.example -&gt; new/Vagrantfile.example<br />#	renamed:    old/cookbooks/apache2 -&gt; new/cookbooks/apache2<br />#	renamed:    old/cookbooks/apt -&gt; new/cookbooks/apt<br />#	renamed:    old/cookbooks/beanstalkd/.travis.yml -&gt; new/cookbooks/beanstalkd/.travis.yml</p></blockquote>

<p>Now we can remove the old folder from the git project and commit the changes.</p>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
$ git rm -r --cached old/
$ git commit -a -m &quot;Moved old to new folder&quot;
$ git push
</pre></div>
</div>
 </figure></notextile></div>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Fixing the clover forcast for PHP projects in Jenkins]]></title>
    <link href="http://lenss.nl/2013/10/clover-forcast-for-php-in-jenkins/"/>
    <updated>2013-10-15T12:26:23+02:00</updated>
    <id>http://lenss.nl/2013/10/clover-forcast-for-php-in-jenkins</id>
    <content type="html"><![CDATA[<p>I had the opportunity to play with <a href="http://jenkins-ci.org/">Jenkins</a> again last week. And the setup for our projects went pretty smooth. But the fact that no matter what i tried. The <a href="https://wiki.jenkins-ci.org/display/JENKINS/Clover+PHP+Plugin">clover</a> forecast icon would always show up as rainy <a href="http://lenss.nl/images/20013/10/health-20to39.png"><img src="http://lenss.nl/images/2013/10/health-20to39.png" alt="" /></a>. While the build was succeeding without issues. So i spend some time googling and trying out multiple “fixes”. Of which none seemed to actually work. I even reverted back to using the Jenkins clover plugins instead of Clover for PHP. No difference at all.</p>

<p>It seemed as if the settings from the config page were completely ignored when calculating the clover status. This was really bugging me. So i checked out the clover plugin source from <a href="https://github.com/jenkinsci/cloverphp-plugin">github</a>. And browsed through the code for a while. When i found the beauty below inside <strong>CoverageTarget.java</strong></p>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
<span class="directive">public</span> <span class="predefined-type">Set</span>&lt;CoverageMetric&gt; getFailingMetrics(AbstractClassMetrics coverage) {
    <span class="predefined-type">Set</span>&lt;CoverageMetric&gt; result = <span class="keyword">new</span> <span class="predefined-type">HashSet</span>&lt;CoverageMetric&gt;();

    <span class="keyword">if</span> (methodCoverage != <span class="predefined-constant">null</span> &amp;&amp; coverage.getMethodCoverage().getPercentage() &lt; methodCoverage) {
        result.add(CoverageMetric.METHOD);
    }

    <span class="keyword">if</span> (statementCoverage != <span class="predefined-constant">null</span> &amp;&amp; coverage.getStatementCoverage().getPercentage() &lt; statementCoverage) {
        result.add(CoverageMetric.STATEMENT);
    }

    <span class="keyword">if</span> (elementCoverage != <span class="predefined-constant">null</span> &amp;&amp; coverage.getElementCoverage().getPercentage() &lt; elementCoverage) {
        result.add(CoverageMetric.ELEMENT);
    }

    <span class="keyword">return</span> result;
}
</pre></div>
</div>
 </figure></notextile></div>

<p>So it seems as if somewhere in the plugin it’s actually calculating the average of the coverage per setting. The strange thing in the method above however is the <strong>elementCoverage</strong> setting. Which is not available in the Jenkins config interface. And causes issues because we have no influence over this setting.</p>

<p>So i added the setting to the config manually</p>

<blockquote><p>$ vi /var/lib/jenkins/jobs/[project]/config.xml</p></blockquote>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
<span class="tag">&lt;org.jenkinsci.plugins.cloverphp.CloverPHPPublisher</span> <span class="attribute-name">plugin</span>=<span class="string"><span class="delimiter">&quot;</span><span class="content">cloverphp@0.3.3</span><span class="delimiter">&quot;</span></span><span class="tag">&gt;</span>
...
      <span class="tag">&lt;healthyTarget&gt;</span>
        <span class="tag">&lt;methodCoverage&gt;</span>20<span class="tag">&lt;/methodCoverage&gt;</span>
        <span class="tag">&lt;statementCoverage&gt;</span>20<span class="tag">&lt;/statementCoverage&gt;</span>
        <span class="tag">&lt;elementCoverage&gt;</span>20<span class="tag">&lt;/elementCoverage&gt;</span>
      <span class="tag">&lt;/healthyTarget&gt;</span>
...
<span class="tag">&lt;/org.jenkinsci.plugins.cloverphp.CloverPHPPublisher&gt;</span>
</pre></div>
</div>
 </figure></notextile></div>

<p>And voilà. I nice sunny <a href="http://lenss.nl/images/20013/10/health-80plus.png"><img src="http://lenss.nl/images/2013/10/health-80plus.png" alt="" /></a> forecast. Now let’s see if i have some time to write a patch for this.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Github, SSH and multiple repositories]]></title>
    <link href="http://lenss.nl/2013/08/github-and-multiple-ssh-keys/"/>
    <updated>2013-08-22T00:02:09+02:00</updated>
    <id>http://lenss.nl/2013/08/github-and-multiple-ssh-keys</id>
    <content type="html"><![CDATA[<p>When working with <a href="http://github.com">Github</a>. Setting up SSH key based authentication is easy. You just create a key. Add the public key in the admin panel and voilà. If a new contributor joins your team. You add his / her key and they also have access.</p>

<p>But how does it work when you have need access to multiple repositories using multiple keys yourself? I had to set this up a couple of times. And it turns out to be just as easy. But if for some reason it’s not that obvious these steps might help.</p>

<p>Let’s pretend we need some key first.</p>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
$ ssh-keygen -t rsa -b 4096
</pre></div>
</div>
 </figure></notextile></div>

<blockquote><p>Generating public/private rsa key pair.<br />Enter file in which to save the key (/home/user/.ssh/id_rsa): repo1_rsa<br />Enter passphrase (empty for no passphrase):<br />Enter same passphrase again:</p><p>Your identification has been saved in repo1_rsa.<br />Your public key has been saved in repo1_rsa.pub.<br />The key fingerprint is:<br />03:b5:da:08:3b:6f:9a:29:3f:f5:4c:ee:5d:14:cb:41 user@host<br />The key&#8217;s randomart image is:<br />+&#8211;[ RSA 4096]&#8212;-+<br />   some output<br />+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+</p></blockquote>

<p>This will generate the public and private key for <strong>repo1</strong>. Now repeat the same thing for <strong>repo2</strong>. Make sure the keys reside in <strong>~/.ssh</strong></p>

<p>Now let’s say we have access to two repositories under two different users / companies. We will use <strong>github.com/repo1</strong> and <strong>github.com/repo2</strong> as examples. The only thing we have to do is add some entries to <strong>~/.ssh/config</strong> to make this work. They key is to use the Github sub-domain mappings</p>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
$ vi ~/.ssh/config
</pre></div>
</div>
 </figure></notextile></div>

<blockquote><p>Host&nbsp;&nbsp;&nbsp;&nbsp;repo1.github.com<br />&nbsp;&nbsp;&nbsp;&nbsp;HostName github.com<br />&nbsp;&nbsp;&nbsp;&nbsp;PreferredAuthentications publickey<br />&nbsp;&nbsp;&nbsp;&nbsp;IdentityFile	~/.ssh/repo1_rsa</p><p>Host&nbsp;&nbsp;&nbsp;&nbsp;repo2.github.com<br />&nbsp;&nbsp;&nbsp;&nbsp;HostName github.com<br />&nbsp;&nbsp;&nbsp;&nbsp;PreferredAuthentications publickey<br />&nbsp;&nbsp;&nbsp;&nbsp;IdentityFile	~/.ssh/repo2_rsa</p></blockquote>

<p>Save the file and we’re done. Now to checkout a project in one of the repositories. Do the following.</p>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
$ git clone git@repo1.github.com:repo1/project.git
</pre></div>
</div>
 </figure></notextile></div>

<blockquote><p>Cloning into &#8216;project&#8217;&#8230;<br />remote: Counting objects: 86, done.<br />remote: Compressing objects: 100% (66/66), done.<br />remote: Total 86 (delta 27), reused 64 (delta 17)<br />Receiving objects: 100% (86/86), 34.83 KiB, done.<br />Resolving deltas: 100% (27/27), done.</p></blockquote>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Memory exhaust issue PHP and APM]]></title>
    <link href="http://lenss.nl/2013/07/memory-exhaust-issue-PHP-and-APM/"/>
    <updated>2013-07-03T11:57:43+02:00</updated>
    <id>http://lenss.nl/2013/07/memory-exhaust-issue-PHP-and-APM</id>
    <content type="html"><![CDATA[<p>A while back i wrote a small data aggregator that would do some background processing and populate a database with it’s calculated results. The main reason to implement this was that running the queries in real-time on the production server was causing memory exhaust issues. Once the new feature was done and deployed. We quickly noticed we were running into the same kind of issues again. And the script would halt almost each time it was executed.</p>

<blockquote><p>Fatal error: Allowed memory size of xxxxxxxxx bytes exhausted (tried toallocate xxxxx bytes) in</p></blockquote>

<p>After some hacking and optimization tricks. The script’s memory consumption seemed stable enough to deploy it to production. However. Each time we deployed it. We were hit by memory exhaust issues almost instantly. Time to do some debugging and code tracing.</p>

<p>And we’re able to narrow it down to a single mysql<em>* (don’t get me started on the mysql</em>* functions, so let’s ignore that for now) call. Namely  <a href="http://php.net/manual/en/function.mysql-fetch-field.php">mysql_fetch_field</a>. Why on earth would this generate a memory exhaust issue on the server you might think. And that’s exactly what we were thinking. </p>

<p>The problem was. That the offset passed in as the field offset was incorrect. And resulted in a notice. These notices however were suppressed with the @ symbol. And therefor never noticeable during development. But that’s no reason for memory exhaust issues… right?</p>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
@mysql_fetch_field($result, $offset);
</pre></div>
</div>
 </figure></notextile></div>

<p>Right! Further inspection showed that in production PHP’s <a href="http://code.google.com/p/peclapm/">APM</a> extension was loaded and active. And this was the real problem behind the memory exhaust issue. Thousands of queries were executed. And almost all of them were throwing an error notice for the fetch field function. Which was ignored by the @ symbol. But APM was still logging them. And apparently had a very hard time keeping up. </p>

<p>It looks like a bug in APM. But that’s another story. The issue was fixed by passing in the correct offset of course. Another nice example of logging bringing down a production server.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[PHP 5.5.0 released]]></title>
    <link href="http://lenss.nl/2013/06/php-55-released/"/>
    <updated>2013-06-22T21:56:12+02:00</updated>
    <id>http://lenss.nl/2013/06/php-55-released</id>
    <content type="html"><![CDATA[<p>PHP reached a new milestone 3 days ago. And as always it’s quite exciting news. Some of the new features are already outlined by Evert Pot’s post which you can find <a href="http://evertpot.com/php-55-released/">here</a>. And all of this of course can be found on the <a href="https://wiki.php.net/rfc">wiki</a> and in the <a href="http://php.net/ChangeLog-5.php#5.5.0">change log</a>. </p>

<p>I’ll just outline some of the new and exiting features, deprecated notices and removed functions.</p>

<p><strong><em>Simplified password hashing API</em></strong></p>

<p>Hashing passwords with <a href="http://php.net/manual/en/function.md5.php">md5()</a> and <a href="http://php.net/manual/en/function.sha1.php">sha1()</a> just isn’t enough anymore. So a new, secure and easy way to hash passwords has been added. And besides hashing includes some other useful functions.</p>

<p><strong><em>$password</em></strong> The password string to hash</p>

<p><strong><em>$algorithm</em></strong> The hashing algorithm to use of which two are available at the moment</p>

<blockquote><p>PASSWORD_DEFAULT which uses bcrypt<br />PASSWORD_BCRYPT which uses blowfish</p></blockquote>

<p><strong><em>$options</em></strong> makes it possible to add a salt or set the cost for the hashing algorithm</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Hash password with default algorithm</span><a href="http://php.net/manual/en/function.password-hash.php">password_hash() </a></figcaption> <div class="CodeRay">
  <div class="code"><pre>
<span class="local-variable">$password</span> = <span class="string"><span class="delimiter">'</span><span class="content">test-password</span><span class="delimiter">'</span></span>;
<span class="local-variable">$hash</span> = password_hash(<span class="local-variable">$password</span>, <span class="constant">PASSWORD_DEFAULT</span>);
<span class="predefined">var_dump</span>(<span class="local-variable">$hash</span>);
</pre></div>
</div>
 </figure></notextile></div>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
string(60) &quot;$2y$10$qGv1q5nT4F7HCtKSPPME2usrdJRcRpk9lEUMQsE8mqyDIy3fbJ4I.&quot;
</pre></div>
</div>
 </figure></notextile></div>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Hash password with BLOWFISH algorithm</span><a href="http://php.net/manual/en/function.password-hash.php">password_hash() </a></figcaption> <div class="CodeRay">
  <div class="code"><pre>
<span class="local-variable">$hash</span> = password_hash(<span class="local-variable">$password</span>, <span class="constant">PASSWORD_BCRYPT</span>);
<span class="predefined">var_dump</span>(<span class="local-variable">$hash</span>);
</pre></div>
</div>
 </figure></notextile></div>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
string(60) &quot;$2y$10$XtpNO/tFjtkq4u3ghcpqXeSwbHZxDQDTXRHfWBnZsmowUVl/MQys2&quot;
</pre></div>
</div>
 </figure></notextile></div>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Hash password with BLOWFISH algorithm and options</span><a href="http://php.net/manual/en/function.password-hash.php">password_hash() </a></figcaption> <div class="CodeRay">
  <div class="code"><pre>
<span class="local-variable">$salt</span> = mcrypt_create_iv(<span class="integer">22</span>, <span class="constant">MCRYPT_DEV_URANDOM</span>); 
<span class="local-variable">$hash</span> = password_hash(<span class="local-variable">$password</span>, <span class="constant">PASSWORD_BCRYPT</span>, <span class="predefined">array</span>(<span class="string"><span class="delimiter">&quot;</span><span class="content">cost</span><span class="delimiter">&quot;</span></span> =&gt; <span class="integer">14</span>, <span class="string"><span class="delimiter">&quot;</span><span class="content">salt</span><span class="delimiter">&quot;</span></span> =&gt; <span class="local-variable">$salt</span>));
<span class="predefined">var_dump</span>(<span class="local-variable">$hash</span>);
</pre></div>
</div>
 </figure></notextile></div>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
string(60) &quot;$2y$14$6ZtnYJ0CyqCUx.vJu3MZEuUGgIN.ryxMa0Yh8BnCrbBDVnd3Me30i&quot;
</pre></div>
</div>
 </figure></notextile></div>

<p>Verify if a hash and password match. Return true if they do and false if they don’t</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Verify hash</span><a href="http://php.net/manual/en/function.password-verify.php">password_verify() </a></figcaption> <div class="CodeRay">
  <div class="code"><pre>
<span class="local-variable">$hash</span> = password_hash(<span class="local-variable">$password</span>, <span class="constant">PASSWORD_DEFAULT</span>);

<span class="keyword">if</span> (password_verify(<span class="local-variable">$password</span>, <span class="local-variable">$hash</span>)) {
  <span class="predefined">echo</span> <span class="string"><span class="delimiter">'</span><span class="content">Password is correct</span><span class="delimiter">'</span></span>;
} <span class="keyword">else</span> {
  <span class="predefined">echo</span> <span class="string"><span class="delimiter">'</span><span class="content">Password is incorrect</span><span class="delimiter">'</span></span>;
}
</pre></div>
</div>
 </figure></notextile></div>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
Password is correct
</pre></div>
</div>
 </figure></notextile></div>

<p>Get information about a valid hash created with password_hash(). The function returns an array with the use d algorithm and options</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Retrieve $hash information</span><a href="http://php.net/manual/en/function.password-get-info.php">password_get_info() </a></figcaption> <div class="CodeRay">
  <div class="code"><pre>
<span class="local-variable">$info</span> = password_get_info(<span class="local-variable">$hash</span>);
</pre></div>
</div>
 </figure></notextile></div>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
array(3) {
  [&quot;algo&quot;]=&gt;
  int(1)
  [&quot;algoName&quot;]=&gt;
  string(6) &quot;bcrypt&quot;
  [&quot;options&quot;]=&gt;
  array(1) {
    [&quot;cost&quot;]=&gt;
    int(10)
  }
}
</pre></div>
</div>
 </figure></notextile></div>

<p>Check if the supplied hash was generated by the provided algorithm and options. This might come in handy when the hash needs to be updated</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Check if a $hash needs to be rehashed</span><a href="http://php.net/manual/en/function.password-needs-rehash.php">password_needs_rehash() </a></figcaption> <div class="CodeRay">
  <div class="code"><pre>
<span class="keyword">if</span> (password_needs_rehash(<span class="local-variable">$hash</span>, <span class="constant">PASSWORD_BCRYPT</span>, <span class="predefined">array</span>(<span class="string"><span class="delimiter">'</span><span class="content">cost</span><span class="delimiter">'</span></span> =&gt; <span class="integer">8</span>))) {
  <span class="comment">// Update the password hash</span>
}
</pre></div>
</div>
 </figure></notextile></div>

<p><strong><em>Support for constant array/string dereferencing</em></strong></p>

<p>If you work with objects you might have worked with object dereferencing. This Is used to chain method calls. Or the so called fluent interfaces</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Dereference object call </span></figcaption>
 <div class="CodeRay">
  <div class="code"><pre>
<span class="local-variable">$obj</span>-&gt;method()-&gt;returnObjMethod();
</pre></div>
</div>
 </figure></notextile></div>

<p>Now the same is possible for arrays and strings</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Dereference strings / array </span></figcaption>
 <div class="CodeRay">
  <div class="code"><pre>
<span class="predefined">echo</span> <span class="predefined">array</span>(<span class="integer">1</span>, <span class="integer">2</span>, <span class="integer">3</span>)[<span class="integer">0</span>]; <span class="comment">//output 1</span>
<span class="predefined">echo</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">foobar</span><span class="delimiter">&quot;</span></span>[<span class="integer">2</span>]; <span class="comment">//output o</span>
<span class="predefined">echo</span> <span class="string"><span class="delimiter">&quot;</span><span class="content">foobar</span><span class="delimiter">&quot;</span></span>[<span class="string"><span class="delimiter">&quot;</span><span class="content">foo</span><span class="delimiter">&quot;</span></span>][<span class="integer">0</span>] <span class="comment">// output f</span>
 
<span class="predefined">echo</span> [<span class="integer">1</span>,<span class="integer">3</span>,<span class="integer">4</span>][<span class="integer">2</span>]; <span class="comment">//output 4</span>
</pre></div>
</div>
 </figure></notextile></div>

<p><strong><em>Class Name Resolution As Scalar Via “class” Keyword</em></strong></p>

<p>An easy way to get the full class name </p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Class name resolution via ::class </span></figcaption>
 <div class="CodeRay">
  <div class="code"><pre>
<span class="keyword">namespace</span> <span class="constant">Vodka</span>\<span class="predefined">Crypt</span>;

<span class="keyword">Class</span> <span class="constant">HashBuilder</span> {}

<span class="keyword">use</span> <span class="constant">Vodka</span>\<span class="predefined">Crypt</span>\<span class="constant">HashBuilder</span>;
         
<span class="predefined">var_dump</span>(<span class="constant">HashBuilder</span>::<span class="keyword">class</span>);
</pre></div>
</div>
 </figure></notextile></div>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
string(23) &quot;Vodka\Crypt\HashBuilder&quot;
</pre></div>
</div>
 </figure></notextile></div>

<p><strong><em>Support for using empty() on the result of function calls and other expressions</em></strong></p>

<p>Normally <a href="http://php.net/manual/en/function.empty.php">empty()</a> and <a href="http://php.net/manual/en/function.isset.php">isset()</a> could only be used on variables. In 5.5 it’s possible to test expression and return values from functions</p>

<p><strong><em>5.3</em></strong></p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Call empty() with closure </span></figcaption>
 <div class="CodeRay">
  <div class="code"><pre>
<span class="predefined">var_dump</span>( <span class="predefined">empty</span>(<span class="keyword">function</span>() {}) );
</pre></div>
</div>
 </figure></notextile></div>

<blockquote><p>PHP Parse error:  syntax error, unexpected T_FUNCTION in</p></blockquote>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Call empty() with function return value </span></figcaption>
 <div class="CodeRay">
  <div class="code"><pre>        
<span class="keyword">function</span> <span class="function">foo</span>() {}
<span class="predefined">var_dump</span>(<span class="predefined">empty</span>(foo()));
</pre></div>
</div>
 </figure></notextile></div>

<blockquote><p>PHP Fatal error:  Can&#8217;t use function return value in write context in</p></blockquote>

<p><strong><em>5.5</em></strong></p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Call empty() with function return value </span></figcaption>
 <div class="CodeRay">
  <div class="code"><pre>
<span class="keyword">function</span> <span class="function">foo</span>(<span class="local-variable">$val</span>) { 
  <span class="keyword">return</span> <span class="local-variable">$val</span>; 
}

<span class="predefined">var_dump</span>( <span class="predefined">empty</span>(foo([])) );
<span class="predefined">var_dump</span>( <span class="predefined">empty</span>(foo(<span class="predefined-constant">true</span>)) );
</pre></div>
</div>
 </figure></notextile></div>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
bool(true)
bool(false)
</pre></div>
</div>
 </figure></notextile></div>

<p><strong><em>Support for list in foreach</em></strong></p>

<p>List has been added for foreach loops. Great for eliminating unused variables.</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Support for list in foreach </span></figcaption>
 <div class="CodeRay">
  <div class="code"><pre>
<span class="local-variable">$messages</span> = <span class="predefined">array</span>(
  <span class="predefined">array</span>(<span class="string"><span class="delimiter">'</span><span class="content">id</span><span class="delimiter">'</span></span> =&gt; <span class="integer">1</span>, <span class="string"><span class="delimiter">'</span><span class="content">body</span><span class="delimiter">'</span></span> =&gt; <span class="string"><span class="delimiter">'</span><span class="content">test-1</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">code</span><span class="delimiter">'</span></span> =&gt; <span class="integer">12</span>),
  <span class="predefined">array</span>(<span class="string"><span class="delimiter">'</span><span class="content">id</span><span class="delimiter">'</span></span> =&gt; <span class="integer">2</span>, <span class="string"><span class="delimiter">'</span><span class="content">body</span><span class="delimiter">'</span></span> =&gt; <span class="string"><span class="delimiter">'</span><span class="content">test-2</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">code</span><span class="delimiter">'</span></span> =&gt; <span class="integer">12</span>),
  <span class="predefined">array</span>(<span class="string"><span class="delimiter">'</span><span class="content">id</span><span class="delimiter">'</span></span> =&gt; <span class="integer">3</span>, <span class="string"><span class="delimiter">'</span><span class="content">body</span><span class="delimiter">'</span></span> =&gt; <span class="string"><span class="delimiter">'</span><span class="content">test-3</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">code</span><span class="delimiter">'</span></span> =&gt; <span class="integer">10</span>)
);

<span class="comment">// Before</span>
<span class="keyword">foreach</span> (<span class="local-variable">$messages</span> <span class="keyword">as</span> <span class="local-variable">$message</span>) {
  <span class="predefined">list</span>(<span class="local-variable">$id</span>, <span class="local-variable">$body</span>) = <span class="local-variable">$message</span>;
}
         
<span class="comment">// After</span>
<span class="keyword">foreach</span> (<span class="local-variable">$messages</span> <span class="keyword">as</span> <span class="predefined">list</span>(<span class="local-variable">$id</span>, <span class="local-variable">$body</span>)) {}
</pre></div>
</div>
 </figure></notextile></div>

<p><strong><em>Zend Opcache extension and enable building it by default</em></strong></p>

<p>My short post about <a href="https://wiki.php.net/rfc/optimizerplus">Zend Optimizer+</a> in February this year. Kind of slipped my mind. And i was somehow under the impression <a href="http://pecl.php.net/package/APC">APC</a> would be integrated. But this of course has to be Zend Optimizer+. Finally an opcode cacher available be default. And configurable from php.ini</p>

<blockquote><p>[opcache]<br />; Determines if Zend OPCache is enabled<br />opcache.enable=0<br />opcache.enable_cli=0</p><p>; The OPcache shared memory storage size.<br />opcache.memory_consumption=64</p><p>; The amount of memory for interned strings in Mbytes.<br />opcache.interned_strings_buffer=4</p><p>; Max files in OPCode cache, use a number between 200 and 100000.<br />opcache.max_accelerated_files=2000</p><p>; The maximum percentage of &#8220;wasted&#8221; memory until a restart is scheduled.<br />opcache.max_wasted_percentage=5</p><p>; Append current working dir to script name<br />opcache.use_cwd=1</p><p>How often a file should be validated<br />opcache.revalidate_freq=2</p><p>; Enables or disables file search in include_path optimization<br />opcache.revalidate_path=0</p><p>; Drop all PHPDoc comments<br />opcache.save_comments=1</p></blockquote>

<p><strong><em>array_column function which returns a column in a multidimensional array</em></strong></p>

<p>Fetching a column from a multi-dimensional array is now possible with a single function call.</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Fetch a column from a multi-dimensional array</span><a href="http://php.net/manual/en/function.array-column.php">array_column() </a></figcaption> <div class="CodeRay">
  <div class="code"><pre>
<span class="local-variable">$nestedArray</span> = <span class="predefined">array</span>(
  <span class="predefined">array</span>(<span class="string"><span class="delimiter">'</span><span class="content">id</span><span class="delimiter">'</span></span> =&gt; <span class="integer">1</span>, <span class="string"><span class="delimiter">'</span><span class="content">body</span><span class="delimiter">'</span></span> =&gt; <span class="string"><span class="delimiter">'</span><span class="content">test-1</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">code</span><span class="delimiter">'</span></span> =&gt; <span class="integer">12</span>),
  <span class="predefined">array</span>(<span class="string"><span class="delimiter">'</span><span class="content">id</span><span class="delimiter">'</span></span> =&gt; <span class="integer">2</span>, <span class="string"><span class="delimiter">'</span><span class="content">body</span><span class="delimiter">'</span></span> =&gt; <span class="string"><span class="delimiter">'</span><span class="content">test-2</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">code</span><span class="delimiter">'</span></span> =&gt; <span class="integer">12</span>),
  <span class="predefined">array</span>(<span class="string"><span class="delimiter">'</span><span class="content">id</span><span class="delimiter">'</span></span> =&gt; <span class="integer">3</span>, <span class="string"><span class="delimiter">'</span><span class="content">body</span><span class="delimiter">'</span></span> =&gt; <span class="string"><span class="delimiter">'</span><span class="content">test-3</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">code</span><span class="delimiter">'</span></span> =&gt; <span class="integer">10</span>)
);
<span class="local-variable">$columns</span> = array_column(<span class="local-variable">$nestedArray</span>, <span class="string"><span class="delimiter">'</span><span class="content">code</span><span class="delimiter">'</span></span>);
<span class="predefined">print_r</span>(<span class="local-variable">$columns</span>);
</pre></div>
</div>
 </figure></notextile></div>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
Array
(
  [0] =&gt; 12
  [1] =&gt; 12
  [2] =&gt; 10
)
</pre></div>
</div>
 </figure></notextile></div>

<p>Or fetch status code indexed by id</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Fetch a column from a multi-dimensional array index by another field</span><a href="http://php.net/manual/en/function.array-column.php">array_column() </a></figcaption> <div class="CodeRay">
  <div class="code"><pre>
<span class="local-variable">$columns</span> = array_column(<span class="local-variable">$nestedArray</span>, <span class="string"><span class="delimiter">'</span><span class="content">code</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">id</span><span class="delimiter">'</span></span>);
<span class="predefined">print_r</span>(<span class="local-variable">$columns</span>);
</pre></div>
</div>
 </figure></notextile></div>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
Array
(
  [145] =&gt; 12
  [20098] =&gt; 12
  [34] =&gt; 10
)
</pre></div>
</div>
 </figure></notextile></div>

<p><strong><em>deprecated</em></strong></p>

<p>The following mcrypt functions have been deprecated <a href="http://php.net/manual/en/function.mcrypt-ecb.php">mcrypt_ecb()</a>, <a href="http://php.net/manual/en/function.mcrypt-cbc.php">mcrypt_cbc()</a>, <a href="http://php.net/manual/en/function.mcrypt-cfb.php">mcrypt_cfb()</a>, <a href="http://php.net/manual/en/function.mcrypt-ofb.php">mcrypt_ofb()</a> and will now throw <a href="http://php.net/manual/en/errorfunc.constants.php">E_DEPRECATED</a>.</p>

<p>The mysql extension has finally been deprecated, and deprecation warnings will be generated when connections are established to databases via <a href="http://php.net/manual/en/function.mysql-connect.php">mysql_connect()</a>, <a href="http://php.net/manual/en/function.mysql-pconnect.php">mysql_pconnect()</a></p>

<p>use <a href="http://php.net/manual/en/book.mysqli.php">MySQLi</a> or <a href="http://php.net/manual/en/ref.pdo-mysql.php">PDO_MySQL</a> extensions instead.</p>

<p><strong><em>removed</em></strong></p>

<p>The following (not so useful) functions have been removed from the core <a href="http://php.net/manual/en/function.php-logo-guid.php">php_logo_guid()</a>, php_egg_logo_guid(), php_real_logo_guid(), <a href="http://www.php.net/manual/en/function.zend-logo-guid.php">zend_logo_guid()</a>. And support for the ancient operating systems Windows XP and 2003 has been dropped!</p>

<p><strong><em>Install 5.5 on Ubuntu (experimental)</em></strong></p>

<p>If you want to experience the new version first hand and you work on <a href="http://www.ubuntu.com/">Ubuntu</a>. You can add the experimental PPA and give it a shot.</p>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
sudo add-apt-repository ppa:ondrej/php5-experimental
sudo apt-get update
sudo apt-get install php5
</pre></div>
</div>
 </figure></notextile></div>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Casting weirdness with PHP]]></title>
    <link href="http://lenss.nl/2013/03/casting-weirdness-with-PHP/"/>
    <updated>2013-03-28T22:20:34+01:00</updated>
    <id>http://lenss.nl/2013/03/casting-weirdness-with-PHP</id>
    <content type="html"><![CDATA[<p>When my coworker today asked if he could cast an array to a object. I couldn’t really answer the question. Don’t think i ever done that. So let’s try. right?</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Cast array to object </span></figcaption>
 <div class="CodeRay">
  <div class="code"><pre>
<span class="local-variable">$arr</span> = <span class="predefined">array</span>(<span class="string"><span class="delimiter">'</span><span class="content">foo</span><span class="delimiter">'</span></span> =&gt; <span class="string"><span class="delimiter">'</span><span class="content">baz</span><span class="delimiter">'</span></span>);
<span class="local-variable">$obj</span> = (<span class="predefined-type">object</span>) <span class="local-variable">$arr</span>;

<span class="predefined">var_dump</span>(<span class="local-variable">$obj</span>);
</pre></div>
</div>
 </figure></notextile></div>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
object(stdClass)#1 (1) {
  [&quot;foo&quot;]=&gt;
  string(3) &quot;baz&quot;
}
</pre></div>
</div>
 </figure></notextile></div>

<p>Ha that’s cool. It actually works. But wait. What happens when we use a numeric index?</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Cast array to object </span></figcaption>
 <div class="CodeRay">
  <div class="code"><pre>
<span class="local-variable">$arr</span> = <span class="predefined">array</span>(<span class="integer">0</span> =&gt; <span class="string"><span class="delimiter">'</span><span class="content">bar</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">foo</span><span class="delimiter">'</span></span> =&gt; <span class="string"><span class="delimiter">'</span><span class="content">baz</span><span class="delimiter">'</span></span>);
<span class="local-variable">$obj</span> = (<span class="predefined-type">object</span>) <span class="local-variable">$arr</span>;

<span class="predefined">var_dump</span>(<span class="local-variable">$obj</span>);
</pre></div>
</div>
 </figure></notextile></div>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
object(stdClass)#1 (2) {
  [0]=&gt;
  string(3) &quot;bar&quot;
  [&quot;foo&quot;]=&gt;
  string(3) &quot;baz&quot;
}
</pre></div>
</div>
 </figure></notextile></div>

<p>WTF? We just created <strong><em>$obj-&gt;0</em></strong> which should not be allowed in PHP as far as i know. So let’s make sure i am not mistaking.</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Assign value to numeric class property </span></figcaption>
 <div class="CodeRay">
  <div class="code"><pre>
<span class="local-variable">$foo</span> = <span class="keyword">new</span> <span class="predefined-constant">stdClass</span>();
<span class="local-variable">$foo</span>-&gt;<span class="integer">0</span> = <span class="string"><span class="delimiter">'</span><span class="content">bar</span><span class="delimiter">'</span></span>;
</pre></div>
</div>
 </figure></notextile></div>

<blockquote><p>PHP Parse error:  syntax error, unexpected &#8216;0&#8217; (T_LNUMBER), expecting identifier (T_STRING) or variable (T_VARIABLE) or &#8216;{&#8217; or &#8216;$&#8217; in foo.php on line 5</p></blockquote>

<p>But casting the array didn’t complain about a thing. Can we access this property? Well! Not calling it directly. At least not that i know of. But looping over the object’s properties does seem to work. </p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Loop object properties </span></figcaption>
 <div class="CodeRay">
  <div class="code"><pre>
<span class="comment">// Parse error</span>
<span class="comment">// var_dump($obj-&gt;0);</span>

<span class="keyword">foreach</span> (<span class="local-variable">$obj</span> <span class="keyword">as</span> <span class="local-variable">$key</span> =&gt; <span class="local-variable">$val</span>) {
  <span class="predefined">var_dump</span>(<span class="local-variable">$key</span>);
  <span class="predefined">var_dump</span>(<span class="local-variable">$obj</span>-&gt;<span class="local-variable">$key</span>);
}
</pre></div>
</div>
 </figure></notextile></div>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
int(0)
PHP Notice:  Undefined property: stdClass::$0 in foo.php on line 14
NULL
string(3) &quot;foo&quot;
string(3) &quot;baz&quot;
</pre></div>
</div>
 </figure></notextile></div>

<p>It’s not that i was planning on ever using this. Or advising other people to use it. In the contrary. But i guess it’s not completely useless. But care is required when doing so.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Zend Optimizer+ integrated into 5.5]]></title>
    <link href="http://lenss.nl/2013/02/zend-optimizer%2B-integrated-in-5.5/"/>
    <updated>2013-02-27T22:12:12+01:00</updated>
    <id>http://lenss.nl/2013/02/zend-optimizer+-integrated-in-5.5</id>
    <content type="html"><![CDATA[<p>It looks like PHP is going to get another built in performance boost. The plan is to integrate and open source the <a href="http://files.zend.com/help/previous-version/Zend-Server-4-Community-Edition/zendoptimizerplus.html">Zend Optimizer+</a> component. The fastest Opcode cacher out there. Zend has provided the source. Which is already available on <a href="http://bit.ly/VSsqx3">github</a>. So we get the Opcode cacher to boost  out applications even more. And the community can extend and built upon the available source code. Win! Win!</p>

<p>PHP 5+ has come a long way performance wise without the Optimizer component. But being able to apply opcode cache out of the box is a great addition. And so far the <a href="http://bit.ly/116BnnB">benchmarks</a> look promising. The Optimizer+ component beats <a href="http://pecl.php.net/package/APC">APC</a> hands down in all performed tests.</p>

<p>Read more about Opcode caching and the integration process <a href="https://wiki.php.net/rfc/optimizerplus">here</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[PHPness Serious WTF]]></title>
    <link href="http://lenss.nl/2013/02/phpness-serious-wtf/"/>
    <updated>2013-02-27T11:58:26+01:00</updated>
    <id>http://lenss.nl/2013/02/phpness-serious-wtf</id>
    <content type="html"><![CDATA[<p>It’s been a while since i last blogged. And i don’t really have anything new to offer. But i would like to comment on some current event. There has been some commotion about a free t shirt that was distributed on the SunshinePHP conference this year. </p>

<p><a href="http://lenss.nl/images/2013/02/web-and-php-img.png"><img src="http://lenss.nl/images/2013/02/web-and-php-img.png" alt="" /></a></p>

<p>The first time i saw the shirt i could not make out what was so offending that people would start blogging about it. Somebody had to point that out for me. So what’s the deal here? Apparently the shirt’s slogan was intentionally created with a slight sexual undertone. The idea comes from the enlarge your penis SPAM we all know! </p>

<p>Some people have perceived this as being sexist. And even go so far as to personally attack the people behind the shirt. </p>

<p>Personally i don’t think the shirt is sexist or offensive at all. And don’t really understand all the fuss. Sex has never been an issue for me in the PHP community. I learn just as much from female developers as i do from the male ones. We are all equal. People that feel the need to defend the opposite sex are probably the ones that see a difference. Even so! Why make such a big deal of something so small? I never seen anybody blog about the programming with attitude poster. </p>

<p><a href="http://lenss.nl/images/2013/02/php-programming.jpg"><img src="http://lenss.nl/images/2013/02/php-programming.jpg" alt="" /></a></p>

<p>I think the PHP community has just lost a bit of it’s shine and coolness. I’ve always been under the impression the PHP community consisted of free thinking people that do what they love. Develop stuff. And that’s exactly what attracted me to it 12 years ago in the first place.</p>

<p>The community has grown quite a lot in that period of time. The thing with every communities is that it brings forth vocal people. Which is a great thing in general. But not so good when people forget their responsibility towards the rest of the community. And that’s exactly what happened the last few days. Personal issues have become public. To me it seems many of you have missed the boat completely. You don’t have to like the shirt. But there is absolutely no reason to bash the initiative in public.</p>

<p>Here are some of the articles the spawned over the last couple days:</p>

<p><a href="http://webandphpmag.wordpress.com/2013/02/25/phpness-gate-raising-interesting-issues/">PHPness Gate – raising interesting issues</a></p>

<p><a href="http://www.brandonsavage.net/on-public-outrage-and-bad-actors/">On Public Outrage And Bad Actors</a></p>

<p><a href="http://caseysoftware.com/blog/sexism-php-community">Sexism in the PHP Community</a></p>

<p><a href="http://www.leftontheweb.com/message/On_SexismRacismAnyotherism_and_the_PHP_Community">On Sexism/Racism/Any-other-ism and the PHP Community</a></p>

<p><a href="http://blog.calevans.com/2013/02/22/sexism-and-php/">Sexism and PHP</a></p>

<p><a href="http://news.ycombinator.com/item?id=5269120">Hacker news - Sexism and PHP (calevans.com)</a></p>

<p><a href="http://www.gogolek.co.uk/blog/2013/02/web-and-php-sexist-tshirt-debate-my-2-cents/">Web &amp; PHP sexist tshirt debate – my 2 cents</a></p>

<p><a href="http://blog.ircmaxell.com/2013/02/on-equality-sexism-and-even-hand.html">On Equality, Sexism and an Even Hand</a></p>

<p>So let’s all just respect one another. And keep the PHP community a friendly place. This kind of nonsense has no positive impact on anybody.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Publish Google Reader shared items]]></title>
    <link href="http://lenss.nl/2012/11/publish-google-reader-shared-items/"/>
    <updated>2012-11-07T15:55:26+01:00</updated>
    <id>http://lenss.nl/2012/11/publish-google-reader-shared-items</id>
    <content type="html"><![CDATA[<p>A lot of people are using the shared items feature in <a href="http://www.google.nl/reader/">Google Reader</a> to publish what they are reading on a blog. It’s like having a live blogroll widget on your website. And gives your readers a good impression of what you are actually interested in.</p>

<p>I never bothered adding this to my blog. But i do like to share. So last night i was trying to figure out how to integrate this with my current blog. I was hoping for an easy implementation. But the information is scarce. So i had to do some digging. I did find a couple of <a href="https://www.google.nl/search?q=wordpress+plugin+google+reader">Wordpress plugins</a>. But most of them were not updated for at least a year. And i am not putting code like that life on my website. </p>

<p>After some Googling i came across a couple of feed URL’s that seem to share their <strong>shared</strong> items in feed form. Using the Google Reader URL and a user id. So the URL for my shared items would look like the one below. Getting your user id by the way is easy. Go to your Google reader page. Click all <strong>All items</strong> and the <strong>UID</strong> will show up in the address bar.</p>

<blockquote>
  <p>http://www.google.com/reader/shared/16525759780220726764</p>
</blockquote>

<p>The problem with this however. Non of my shared posts show up on this page. And i have not figured out a way to populate it just yet. So i came up with an other path to get this data on my server.</p>

<p>In the Google Reader pages it’s possible to add sharing functionality. This is done by going to the <strong>Send To</strong> tab</p>

<p><a href="http://lenss.nl/images/2012/11/Send-To.png"><img src="http://lenss.nl/images/2012/11/Send-To-300x22.png" alt="" /></a></p>

<p>From here it’s possible to select a service to share data with. Non of these services are any good for what i am trying to do. But the great thing about this page is. You can provide custom URL’s for sharing data. Just incorporate the specified parameters in the URL and your done.</p>

<p><a href="http://lenss.nl/images/2012/11/Custom-Site.png"><img src="http://lenss.nl/images/2012/11/Custom-Site-300x178.png" alt="" /></a></p>

<p>Once configured and saved a custom URL is visible in the <strong>Send To</strong> panel</p>

<p><a href="http://lenss.nl/images/2012/11/Favorite-Site.png"><img src="http://lenss.nl/images/2012/11/Favorite-Site-300x125.png" alt="" /></a></p>

<p>That’s it for this part. Actually sharing items is quite easy now. When back in the Google Reader under each post there is Send to link. If you click this link the newly created custom URL will show up. And you can share the post.</p>

<p><a href="http://lenss.nl/images/2012/11/Tag-Article.png"><img src="http://lenss.nl/images/2012/11/Tag-Article-300x41.png" alt="" /></a></p>

<p>The only thing left to do is write some code to process the incoming data. To get you started. Some of the code i used while testing this is posted below</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>GoogleReaderShare class </span></figcaption>
 <div class="CodeRay">
  <div class="code"><pre>
<span class="keyword">Class</span> <span class="constant">GoogleReaderShare</span>
{
  <span class="keyword">const</span> <span class="constant">GOOGLE_REMOTE_IP</span> = <span class="string"><span class="delimiter">'</span><span class="content">95.97.54.3</span><span class="delimiter">'</span></span>;
            
  <span class="keyword">const</span> <span class="constant">GOOGLE_REFERER</span> = <span class="string"><span class="delimiter">'</span><span class="content">http://www.google.nl/reader/view/</span><span class="delimiter">'</span></span>;
            
  <span class="keyword">protected</span> <span class="keyword">static</span> <span class="local-variable">$_whitelist</span> = <span class="predefined">array</span>(<span class="string"><span class="delimiter">'</span><span class="content">source</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">title</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">url</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">short</span><span class="delimiter">'</span></span>);
            
  <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">function</span> <span class="function">CheckSource</span>(<span class="local-variable">$remoteAddr</span>, <span class="local-variable">$referer</span>) 
  {
    <span class="keyword">if</span> ((<span class="local-variable">$remoteAddr</span> == <span class="predefined-constant">self</span>::<span class="constant">GOOGLE_REMOTE_IP</span>) 
        &amp;&amp; (<span class="local-variable">$referer</span> == <span class="predefined-constant">self</span>::<span class="constant">GOOGLE_REFERER</span>)) {
      <span class="keyword">return</span> <span class="predefined-constant">true</span>;
    }
    <span class="keyword">return</span> <span class="predefined-constant">false</span>;
  }
            
  <span class="keyword">protected</span> <span class="keyword">static</span> <span class="keyword">function</span> <span class="function">_CheckIncomingData</span>(<span class="local-variable">$data</span>)
  {
    <span class="keyword">if</span> (!<span class="predefined">is_array</span>(<span class="local-variable">$data</span>)) {
      <span class="keyword">return</span> <span class="predefined-constant">false</span>;
    }
                            
    <span class="keyword">foreach</span> (<span class="local-variable">$data</span> <span class="keyword">as</span> <span class="local-variable">$key</span> =&gt; <span class="local-variable">$value</span>) {
      <span class="keyword">if</span> (!<span class="predefined">in_array</span>(<span class="local-variable">$key</span>, <span class="predefined-constant">self</span>::<span class="local-variable">$_whitelist</span>)) {
        <span class="keyword">return</span> <span class="predefined-constant">false</span>;
      }
    }
  }
            
  <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">function</span> <span class="function">Process</span>(<span class="local-variable">$data</span>) 
  {
    <span class="keyword">if</span> (!<span class="predefined-constant">self</span>::_CheckIncomingData(<span class="local-variable">$data</span>)) {
      <span class="keyword">throw</span> <span class="keyword">new</span> <span class="predefined-constant">Exception</span>(<span class="string"><span class="delimiter">&quot;</span><span class="content">Unrecognized or no incoming data</span><span class="delimiter">&quot;</span></span>);
    }
                    
    <span class="comment">// process the data</span>
  }
 
  <span class="keyword">if</span> (<span class="constant">GoogleReaderShare</span>::<span class="constant">CheckSource</span>(<span class="predefined">$_SERVER</span>[<span class="string"><span class="delimiter">'</span><span class="content">REMOTE_ADDR</span><span class="delimiter">'</span></span>], <span class="predefined">$_SERVER</span>[<span class="string"><span class="delimiter">'</span><span class="content">HTTP_REFERER</span><span class="delimiter">'</span></span>])) {
    <span class="constant">GoogleReaderShare</span>::<span class="constant">Process</span>(<span class="predefined">$_GET</span>);
  }
</pre></div>
</div>
 </figure></notextile></div>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Long running PHP script and MySQL server gone away]]></title>
    <link href="http://lenss.nl/2012/10/long-running-php-script-and-mysql-server-gone-away/"/>
    <updated>2012-10-29T14:39:26+01:00</updated>
    <id>http://lenss.nl/2012/10/long-running-php-script-and-mysql-server-gone-away</id>
    <content type="html"><![CDATA[<p>At the moment i am writing some workers that interact with a <a href="http://kr.github.com/beanstalkd/">beanstalk</a> server. When data gets pushed into the beanstalk server. My workers will be triggered to process this data. So the workers are sitting idle for most of the time. And just wait for some data to process. No rocket science there. But during testing i kept running into <a href="http://www.mysql.com/">MySQL</a> issues. The script seemed to lose connection to the MySQL server when it was idle for longer then a minute. And would respond with a </p>

<blockquote>
  <p>Warning: <a href="http://php.net/mysql_query">mysql_query</a>(): MySQL server has gone away in /path/to/some/mysql4/class.php on line xxx</p>
</blockquote>

<p>So whats going on here? Well actually it’s quite simple. When my script initializes the database connection it doesn’t use it. It just sits there waiting for incoming data. Once received it will process it and try to store it in the database. But when the waiting period exceeds the time for PHP to keep the MySQL connection open it responds with the warning mentioned above. Now in previous versions of PHP this would not be a big issue. As PHP would just initiate a reconnect when the connection is lost. But from PHP 5.0.3 and up this functionality has been disabled by default. For MySQLI this is no problem at all. </p>

<p>MySQLi:</p>

<blockquote>
  <p>mysqli.reconnect = Off to On</p>
</blockquote>

<p>Unfortunately i am working with PHP’s core mysql_* functions (don’t get me started) and there doesn’t seem to be an easy way to resolve this. According to the MySQL documentation</p>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
mysql_options(&amp;mysql, <span class="constant">MYSQL_OPT_RECONNECT</span>, &amp;reconnect);
</pre></div>
</div>
 </figure></notextile></div>

<p>Should do the trick. But passing <strong>MYSQL_OPT_RECONNECT</strong> in anyway to <a href="http://php.net/mysql_connect">mysql_connect</a> didn’t give me the result i was looking for. So what now? Porting the database code to make use of the newer and better PDO or MySQLi is no option. As it would consume way to much time. Fortunately the mysql_* core functions come with mysql_ping. I never had to use this before. But in this case it comes in quite handy.</p>

<p><strong>From the PHP manual:</strong></p>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
<span class="predefined-type">bool</span> mysql_ping ([ <span class="predefined-type">resource</span> <span class="local-variable">$link_identifier</span> = <span class="predefined-constant">NULL</span> ] )
</pre></div>
</div>
 </figure></notextile></div>

<blockquote>
  <p>Checks whether or not the connection to the server is working. If it has gone down, an automatic reconnection is attempted. This function can be used by scripts that remain idle for a long while, to check whether or not the server has closed the connection and reconnect if necessary.</p>
</blockquote>

<p>Note:
<strong>Automatic reconnection is disabled by default in versions of MySQL &gt;= 5.0.3.</strong></p>

<p>Adding the mysql_ping function call was rather straight forward. And didn’t require all that much work to be done. I extended the database class to include a ping method. That would simply throw an exception when it failed to reconnect. </p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>MySQL ping function </span></figcaption>
 <div class="CodeRay">
  <div class="code"><pre>
<span class="keyword">public</span> <span class="keyword">function</span> <span class="function">ping</span>()
{
  <span class="keyword">if</span> (!mysql_ping(<span class="local-variable">$this</span>-&gt;db_connect_id)) {
    <span class="keyword">throw</span> <span class="keyword">new</span> <span class="constant">Mollie_Database_Exception</span>(<span class="string"><span class="delimiter">&quot;</span><span class="content">Connection was lost</span><span class="delimiter">&quot;</span></span>);
  }        
  <span class="keyword">return</span> <span class="predefined-constant">true</span>;
}
</pre></div>
</div>
 </figure></notextile></div>

<p>And after that i started poking around the userland implementation. The worker is running inside a <strong>while(true)</strong> loop. A first test with <strong>-&gt;ping()</strong> being called inside this loop proved to resolve the issue at hand. But running the ping function that often is overkill. And who knows it might actually result in <strong>DoS</strong> of the database server. So i decided to ping the server every one minute or so.</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Keep the connection alive </span></figcaption>
 <div class="CodeRay">
  <div class="code"><pre>
<span class="local-variable">$start</span> = <span class="predefined">time</span>();
<span class="keyword">while</span> (<span class="predefined-constant">true</span>) 
{
  <span class="local-variable">$this</span>-&gt;_keepConnectionAlive(<span class="local-variable">$start</span>);
}
</pre></div>
</div>
 </figure></notextile></div>

<p>And the keepConnectionAlive method looks something like this</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>keepConnectionAlive method </span></figcaption>
 <div class="CodeRay">
  <div class="code"><pre>
<span class="keyword">protected</span> <span class="keyword">function</span> <span class="function">_keepConnectionAlive</span>(&amp;<span class="local-variable">$start</span>)
{
  <span class="local-variable">$passed</span> = (<span class="predefined">time</span>() - <span class="local-variable">$start</span>);
  <span class="keyword">if</span> (<span class="local-variable">$passed</span> &gt; <span class="integer">60</span>)
  {
    <span class="local-variable">$start</span> = <span class="predefined">time</span>();
    <span class="local-variable">$this</span>-&gt;_db-&gt;ping();
  }
}
</pre></div>
</div>
 </figure></notextile></div>

<p>I’m not a big fan of this solution. And would rather be implementing MySQLi functions. But this functions well. And will do for now.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Git: Rebase on pull by default]]></title>
    <link href="http://lenss.nl/2012/10/git-rebase-on-pull-by-default/"/>
    <updated>2012-10-25T14:20:22+02:00</updated>
    <id>http://lenss.nl/2012/10/git-rebase-on-pull-by-default</id>
    <content type="html"><![CDATA[<p>I was a bit surprised today when <a href="http://git-scm.com/">git</a> presented me a merge message window after i did a pull. This should not happen as the normal behavior here should be to <a href="http://git-scm.com/book/en/Git-Branching-Rebasing">rebase</a> the changes. But apparently that didn’t happen this time. When i asked one of the other <a href="http://www.scriptorama.nl/">dev</a> ‘s what could be the issue. We quickly figured out i was just missing some <strong>config</strong> entry in <strong>.git/config</strong>. This probably happened some time ago when i did a fresh checkout.</p>

<p>So to make sure rebasing is done by default. You can run a simple git command or modify the <strong>.git/config</strong> file manually.</p>

<blockquote>
  <p>$ git config branch.autosetuprebase always</p>
</blockquote>

<p>or do</p>

<blockquote>
  <p>$ vi .git/config</p>
</blockquote>

<p>Make sure <strong>[branch “master”]</strong> has <strong>rebase</strong> set to true. It should look like the snippet below.</p>

<blockquote>
  <p>[branch “master”]
	remote = origin
	merge = refs/heads/master
	rebase = true</p>
</blockquote>

<p>Starting to really like git. A couple of more quirks and things will be running fine.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Workaround Ubuntu 12.04 mysterious system freezes]]></title>
    <link href="http://lenss.nl/2012/10/workaround-ubuntu-12-04-mysterious-system-freezes/"/>
    <updated>2012-10-12T15:43:46+02:00</updated>
    <id>http://lenss.nl/2012/10/workaround-ubuntu-12-04-mysterious-system-freezes</id>
    <content type="html"><![CDATA[<p>I have two machines running <a href="http://releases.ubuntu.com/12.04/">Ubuntu 12.04</a>. One of them is very stable. And hardly ever gets rebooted. The other machine is displaying some odd behavior every now and then. And with odd behavior i mean. It just completely freezing up. The only thing functioning at that moment is the mouse.</p>

<p>I use this machine daily. And i can’t afford to lose work due to system crashes. So i could spend numerous hours trying to figure out what’s going on. But that’s probably something better left for the Ubuntu devs them selfs. Besides that there are plenty of bug reports floating around that describe this behavior. And one of those <a href="https://bugs.launchpad.net/ubuntu/+source/linux/+bug/999910">posts</a> seemed to resolve the issue for me. </p>

<p>Apparently the bug that causes these crashes is fixed in 12.10. But the changes will only be backported when 12.10 is released. So that leaves me in quite a pickle. But according to the thread. Upgrading the kernel should do the trick. So that’s exactly what i did. The kernel packages i used can be found here <a href="http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.4-precise/">http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.4-precise/</a></p>

<blockquote>
  <ul>
    <li>$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.4-precise/linux-headers-3.4.0-030400_3.4.0-030400.201205210521_all.deb </li>
    <li>$ sudo dpkg -i linux-headers-3.4.0-030400_3.4.0-030400.201205210521_all.deb</li>
  </ul>
</blockquote>

<blockquote>
  <ul>
    <li>$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.4-precise/linux-headers-3.4.0-030400-generic_3.4.0-030400.201205210521_amd64.deb</li>
    <li>$ sudo dpkg -i linux-headers-3.4.0-030400-generic_3.4.0-030400.201205210521_amd64.deb</li>
  </ul>
</blockquote>

<blockquote>
  <ul>
    <li>$ wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v3.4-precise/linux-image-3.4.0-030400-generic_3.4.0-030400.201205210521_amd64.deb</li>
    <li>$ sudo dpkg -i linux-image-3.4.0-030400-generic_3.4.0-030400.201205210521_amd64.deb</li>
  </ul>
</blockquote>

<p>This comes with a downside of course. All modules compiled for the current kernel need to be recompiled. And i haven’t figured out how to rebuild all of them at once. So i just ran the command below for <a href="https://www.virtualbox.org/">VirtualBox</a> and the <a href="http://www.nvidia.com">NVidia</a> drivers.</p>

<blockquote>
  <p>$ sudo dpkg-reconfigure package-name</p>
</blockquote>

<p>It’s probably a better idea to keep the stable kernel for now. But if system crashes are really bugging you. Then this might resolve the issue. Just be careful.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Fixing character replacement in Wordpress]]></title>
    <link href="http://lenss.nl/2012/09/fixing-character-replacement-in-wordpress/"/>
    <updated>2012-09-24T21:39:17+02:00</updated>
    <id>http://lenss.nl/2012/09/fixing-character-replacement-in-wordpress</id>
    <content type="html"><![CDATA[<p>This has been bugging me for a while. But not enough to actually look into it. And Google searches for <a href="http://wordpress.org/">Wordpress</a> display wrong characters results in a whole forest of threads about UTF-8 encoding. This has nothing to do with that. So what’s the issue here?</p>

<p>Wordpress is replacing characters in my posts. The most annoying being the replacement of – <del>is</del> with - . Which makes no sense at all. Specially when creating code samples. Or command line parameters. My thought is why on earth would you do that? But it probably has something to do with typography…</p>

<p>Anyways. Searching for it today made me stumble onto <a href="http://blog.paulbetts.org/index.php/2007/06/01/stop-wordpress-from-turning-double-dash-into-long-dash/">this</a> post from 2007 by <a href="http://blog.paulbetts.org/">Paul Betts</a>. And believe it or not. Wordpress is still doing that. The code has changed slightly tough. So i created a quick patch as a temporary solution. And need to figure out if this can be circumvented by a plugin or something. If that doesn’t exists already :)</p>

<p>The patch will replace the following lines</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Original replacement arrays </span></figcaption>
 <div class="CodeRay">
  <div class="code"><pre>
<span class="local-variable">$static_characters</span> = <span class="predefined">array_merge</span>( <span class="predefined">array</span>( <span class="string"><span class="delimiter">'</span><span class="content">---</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content"> -- </span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">--</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content"> - </span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">xn-</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">...</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">``</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="char">\'</span><span class="char">\'</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content"> (tm)</span><span class="delimiter">'</span></span> ), <span class="local-variable">$cockney</span> );
<span class="local-variable">$static_replacements</span> = <span class="predefined">array_merge</span>( <span class="predefined">array</span>( <span class="local-variable">$em_dash</span>, <span class="string"><span class="delimiter">'</span><span class="content"> </span><span class="delimiter">'</span></span> . <span class="local-variable">$em_dash</span> . <span class="string"><span class="delimiter">'</span><span class="content"> </span><span class="delimiter">'</span></span>, <span class="local-variable">$en_dash</span>, <span class="string"><span class="delimiter">'</span><span class="content"> </span><span class="delimiter">'</span></span> . <span class="local-variable">$en_dash</span> . <span class="string"><span class="delimiter">'</span><span class="content"> </span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">xn--</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">…</span><span class="delimiter">'</span></span>, <span class="local-variable">$opening_quote</span>, 
  <span class="local-variable">$closing_quote</span>, <span class="string"><span class="delimiter">'</span><span class="content"> ™</span><span class="delimiter">'</span></span> ), <span class="local-variable">$cockneyreplace</span> 
);
</pre></div>
</div>
 </figure></notextile></div>

<p>With</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption class="code-header" style="margin-bottom:-5px;"><span>Updated replacement arrays </span></figcaption>
 <div class="CodeRay">
  <div class="code"><pre>
<span class="local-variable">$static_characters</span> = <span class="local-variable">$cockney</span>;
<span class="local-variable">$static_replacements</span> = <span class="local-variable">$cockneyreplace</span>;
</pre></div>
</div>
 </figure></notextile></div>

<p>Patching the file is easy.</p>

<p><strong>This patch was created for v3.4.2. And will most likely fail on other versions of Wordpress.</strong></p>

<blockquote>
  <p>$ cd wp-includes/
$ wget <a href="https://raw.github.com/tlenss/misc/master/patch/wordpress-charreplace.patch">https://raw.github.com/tlenss/misc/master/patch/wordpress-charreplace.patch</a>
$ patch -p0 &lt; wordpress-charreplace.patch
patching file formatting.php</p>
</blockquote>

<p>That’s all.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Resize a Vagrant VMDK drive]]></title>
    <link href="http://lenss.nl/2012/09/resize-a-vagrant-vmdk-drive/"/>
    <updated>2012-09-24T14:17:00+02:00</updated>
    <id>http://lenss.nl/2012/09/resize-a-vagrant-vmdk-drive</id>
    <content type="html"><![CDATA[<p>Using <a href="http://vagrantup.com/">Vagrant</a> as a development environment is great. But you have to watch the available disk space when doing some funky database benchmarking. Last Friday i wrote a script to populate a test database with over 60 million records. And left it running over the weekend. With the idea it would be finished when i returned to the office on Monday. Well it actually was still running. But the Vagrant instance was out of disk space when i logged in. Damn. Should have made sure i had a big disk attached to this instance.</p>

<p>O well. My first idea was to just drop the database that i wanted to use for testing. But due to no space available on the system. I could not drop it. I really couldn’t do anything on the system. Even writing config files failed. So where did all the disk space go?</p>

<blockquote>
  <ul>
    <li>$ df -h</li>
    <li>Filesystem            Size    Used    Avail    Use%    Mounted on</li>
    <li>/dev/mapper/debian-605-root    10G    9.8G    0.2G    99%    /</li>
  </ul>
</blockquote>

<p>That’s really not that much space left. And /var/mysql/ibdata1 for the <a href="http://www.innodb.com/">InnoDB</a> tables was taking up 7 GB. And since i have a couple of InnoDB tables i can’t just delete this file. So need to come up with something else. And after a bit of Googling. I came across <a href="http://jjperezaguinaga.wordpress.com/2012/04/03/a-happy-ending-story-with-vagrant-resizing-a-lucid32-vmdk-box/">this</a> post. Which seemed promising. But the most important part is left out. And instead linked to some horrible garbled page. That is completely unreadable. So i had to do some digging to figure this out on my own. For cloning the disks i followed the steps in the article however. The Virtual Box files are located in the user folder in the following path</p>

<blockquote>
  <p>$ cd ~/VirtualBox VMs/development_*</p>
</blockquote>

<p>The first thing i did was convert the <a href="http://sanbarrow.com/vmdk-handbook.html">VMDK</a> image to a <a href="http://en.wikipedia.org/wiki/VDI_(file_format)">VDI</a> image so we can actually do some partition resizing.</p>

<blockquote>
  <p>$ VBoxManage clonehd box-disk1.vmdk box-disk1.vdi –format VDI</p>
</blockquote>

<p>So now we have a new VDI image. And we need to resize it so it has sufficient space for what we are trying to do. In my case 20 GB is sufficient.</p>

<blockquote>
  <p>$ VBoxManage modifyhd box-disk1.vdi –resize 20000</p>
</blockquote>

<p>Now that the new disk is created it needs to be attached to the vagrant virtual machine. This is easily achieved by doing right click on the VM in <a href="https://www.virtualbox.org/">VirtualBox</a> and select Settings</p>

<blockquote>
  <p>Storage &gt; SATA Controller &gt; Add hard disk (select existing and point to the new VDI image)</p>
</blockquote>

<p>Now boot the Vagrant image in VirtualBox so we have a screen to work with. When it has booted up. Login.</p>

<p>First create a new Primary partition in the unused space of type Linux LVM (8e) with <a href="http://linux.die.net/man/8/cfdisk">cfdisk</a>. </p>

<blockquote>
  <p>$ cfdisk /dev/sda</p>
</blockquote>

<p>When the partition table has been written. It’s time to create a new physical volume on the new partition with the help of <a href="http://linux.about.com/library/cmd/blcmdl8_pvcreate.htm">pvcreate</a></p>

<blockquote>
  <ul>
    <li>$ pvcreate /dev/sda3
      <ul>
        <li>successfully created</li>
      </ul>
    </li>
  </ul>
</blockquote>

<p>For the next steps we will be needing the Volume Group name. We will get this by running <a href="http://linux.about.com/library/cmd/blcmdl8_pvdisplay.htm">pvdisplay</a></p>

<blockquote>
  <ul>
    <li>
      <table>
        <tbody>
          <tr>
            <td>$ pvdisplay</td>
            <td>grep “VG Name”</td>
          </tr>
        </tbody>
      </table>
    </li>
    <li>VG Name    debian-605</li>
  </ul>
</blockquote>

<p>So now we have all the bits ready. And its time to extend the root partition with the newly created partition.</p>

<blockquote>
  <ul>
    <li>$ vgextend debian-605 /dev/sda3</li>
    <li>Volume group “debian-605” successfully extended</li>
  </ul>
</blockquote>

<p>Awesome! next step extending the logical partition</p>

<blockquote>
  <ul>
    <li>$ lvextend /dev/debian-605/root /dev/sda3</li>
    <li>Extending logical volume root to 18.84 GiB</li>
    <li>Logical volume root successfully resized</li>
  </ul>
</blockquote>

<p>Almost there. The last thing left to do is resize the filesystem to make all space available.</p>

<blockquote>
  <ul>
    <li>$ resize2fs /dev/debian-605/root</li>
    <li>resize2fs 1.41.12 (17-May-2010)</li>
    <li>Filesystem at /dev/debian-605/root is mounted on /; on-line resizing required old desc_blocks = 1, new_desc_blocks = 2</li>
    <li>Performing an on-line resize of /dev/debian-605/root to 4937728 (4k) blocks.</li>
    <li>The filesystem on /dev/debian-605/root is now 4937728 blocks long.</li>
  </ul>
</blockquote>

<p>It’s that simple really. So let’s check.</p>

<blockquote>
  <ul>
    <li>$ df -h</li>
    <li>Filesystem            Size    Used    Avail    Use%    Mounted on</li>
    <li>/dev/mapper/debian-605-root    19G    8.6G    9.1G    49%    /</li>
  </ul>
</blockquote>

<p>After this i did not bother to convert the VDI image back to a VDMK image. But if you have to for some reason. You could do that with the commands below. And some manual editing of the VirtualBox xml config.</p>

<blockquote>
  <ul>
    <li>$ VBoxManage internalcommands sethduuid box-disk1.vdi</li>
    <li>$ VBoxManage clonehd box-disk1.vdi box-disk1.vmdk –format VMDK</li>
  </ul>
</blockquote>

<p>So that’s it really for resizing the Vagrant hard drive. The only thing left for me was to cleanup the large ibdata1 file. And setup Mysql to use separate ibdata files for InnoDB table.</p>

<blockquote>
  <ul>
    <li>$ vi /etc/mysql/my.cnf</li>
    <li>[mysqld]</li>
    <li>innodb_file_per_table</li>
  </ul>
</blockquote>

<p>Restart Mysql and dump all needed databases except the system tables like (mysql, information_schema).</p>

<blockquote>
  <ul>
    <li>$ /etc/init.d/mysql restart</li>
    <li>
      <table>
        <tbody>
          <tr>
            <td>$ echo ‘show databases;’</td>
            <td>mysql -uroot -p</td>
            <td>grep -v ^Database$</td>
            <td>grep -v ^information_schema$</td>
            <td>grep -v ^mysql$</td>
            <td>xargs mysqldump -uroot -p  –databases &gt; dump.sql</td>
          </tr>
        </tbody>
      </table>
    </li>
  </ul>
</blockquote>

<p>When that’s done. Drop all InnoDB database tables. Remove the ibdata and in_log files from /var/lib/mysql.</p>

<blockquote>
  <ul>
    <li>$ /etc/init.d/mysql stop</li>
    <li>$ rm /var/mysql/ibdata1* /var/mysql/ib_log*</li>
  </ul>
</blockquote>

<p>Now we restart Mysql. And reimport the databases.</p>

<blockquote>
  <ul>
    <li>$ /etc/init.d/mysql start</li>
    <li>$ mysql -uroot -p &lt; dump.sql</li>
  </ul>
</blockquote>

<ul>
  <li>Some of the resources i used for solving this issue:</li>
  <li>[1] <a href="http://www.turnkeylinux.org/blog/extending-lvm">http://www.turnkeylinux.org/blog/extending-lvm</a></li>
  <li>[2] <a href="http://unix.stackexchange.com/questions/37900/gparted-live-cd-cant-resize-a-partition">http://unix.stackexchange.com/questions/37900/gparted-live-cd-cant-resize-a-partition</a></li>
  <li>[3] <a href="http://www.my-guides.net/en/guides/general-software/122-how-to-resize-a-virtualbox-disk-partition">http://www.my-guides.net/en/guides/general-software/122-how-to-resize-a-virtualbox-disk-partition</a></li>
  <li>[4] <a href="http://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvdi">http://www.virtualbox.org/manual/ch08.html#vboxmanage-modifyvdi</a></li>
  <li>[5] <a href="http://stackoverflow.com/questions/3456159/how-to-shrink-purge-ibdata1-file-in-mysql">http://stackoverflow.com/questions/3456159/how-to-shrink-purge-ibdata1-file-in-mysql</a></li>
</ul>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[GIT:  Coming up with a good workflow]]></title>
    <link href="http://lenss.nl/2012/09/git-coming-up-with-a-good-workflow/"/>
    <updated>2012-09-12T09:09:37+02:00</updated>
    <id>http://lenss.nl/2012/09/git-coming-up-with-a-good-workflow</id>
    <content type="html"><![CDATA[<p>A new environment to work in always brings new challenges. And this one is no exception. And i will be working with <a href="http://git-scm.com/">git</a> from now on. I tried switching before. But always went back to subversion. Because of my job. And for somebody who worked with <a href="http://subversion.apache.org/">subversion</a> solely for the past… say 5 to 7 years it’s kind of a new concept and takes some time to get a grasp on. Ok ok. It’s just another version control system. But it takes some getting used to.</p>

<p>And two days ago i kinda got stuck in <a href="http://git-scm.com/docs/git-rebase">rebase</a> hell. And had to take some time to figure this all out without doing any damage. Which resulted in another problem. There simply is no revert command like in subversion. But git is pretty smart about this kinda things. So getting the branch full of failed merges back to it’s original state can easily be achieved with two commands and some concentration.</p>

<p>First check the <strong>reflog</strong> for a point where to start from</p>

<blockquote>
  <p>$ git reflog</p>
</blockquote>

<p>From the output pick the point where to revert back to. Which looks something like HEAD{2}. And run</p>

<blockquote>
  <p>$ git reset –hard HEAD{2}  </p>
</blockquote>

<p>So back to square one. My main problem was that i had not kept my branch up to date with the remote repository. Which you can do with the pull command while on the master branch. Or with the <strong>rebase</strong> command while working on a local branch. <strong>Rebase</strong> is git’s alternative way of bringing changes together. So the idea behind it is that when your local branch is up to date. The final merge will become as straight forward as possible. </p>

<p>I finally managed to get my changes merged in to master. But did not feel very confident about the whole process. So I  need to come up with a steady work flow. And stick to it. To not waste time and run into these <strong>rebase</strong> disasters.</p>

<p>This is what i have so far. And seems to be a solid routine. Start with a nice new checkout of the project at hand. And branch it for the changes to be done.</p>

<blockquote>

  <ul>
    <li>$ git clone git://some.repository.url:repos.git</li>
    <li>$ git branch dev-branch</li>
  </ul>
</blockquote>

<p>After working on the newly created branch for a while. Some changes are bound to be ready to be pulled into master. Keeping an eye on the build logs or commit messages should work fine. When this happens it’s time to bring those changes into the dev-branch. After pulling them into master.</p>

<blockquote>

  <ul>
    <li>$ git checkout master</li>
    <li>$ git pull</li>
    <li>$ git checkout dev-branch</li>
  </ul>
</blockquote>

<p>If there is a need to <strong>rebase</strong> the branch with for instance master. This is the moment. This might cause <a href="http://stackoverflow.com/questions/559917/git-rebase-and-git-push-non-fast-forward-why-use">non-fast-forward issues</a>. But i have not completely figured out why i run into these issues every now and then. A way to solve this might be to use the <em>–force</em> switch when pushing to remote. But i am not a big fan of forcing things like this.</p>

<blockquote>

  <p>$ git rebase</p>
</blockquote>

<p>If everything is fine some more work can be done on the dev branch. Until a new change in master is ready to be pulled in. In which case it’s rinse and repeat the previous part. When the changeset is ready to be merged back into master. Switch to master bring it up up o date with a pull. And merge the changes from the dev-branch.</p>

<blockquote>

  <ul>
    <li>$ git checkout master</li>
    <li>$ git pull</li>
    <li>$ git push dev-branch</li>
  </ul>
</blockquote>

<p>Again when all is fine all changes will be available in master. If something goes wrong during git-rebase and / or merging. Git will kindly state so. And some manual merging with git’s <a href="http://git-scm.com/docs/git-mergetool">mergetool</a> will have to be done. But that’s something for another day.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Workaround for running WoW with patch 5.0.4 on Ubuntu]]></title>
    <link href="http://lenss.nl/2012/09/workaround-for-running-wow-with-patch-5-0-4-on-ubuntu/"/>
    <updated>2012-09-02T23:48:36+02:00</updated>
    <id>http://lenss.nl/2012/09/workaround-for-running-wow-with-patch-5-0-4-on-ubuntu</id>
    <content type="html"><![CDATA[<p>After a fresh install i couldn’t get <a href="http://eu.battle.net/wow/en/">WoW</a> to work. I’m not that big on playing games lately. But this bugged me. Good thing we have the interwebs.</p>

<p>Starting the battle.net agent manually before firing up the WoW launcher solved the launcher crashing.</p>

<blockquote>
  <ul>
    <li>wine ~/.wine/drive_c/users/Public/Application\ Data/Battle.net/Agent/Agent.1267/Agent.exe –nohttpauth &amp;</li>
    <li>wine ~/.wine/drive_c/Program\ Files\ (x86)/World\ of\ Warcraft/Launcher.exe &amp;</li>
  </ul>
</blockquote>

<p>And installing <strong>vcrun2008</strong> with <a href="http://wiki.winehq.org/winetricks/">winetricks</a> solved the problem with the updater hanging.</p>

<ul>
  <li>[1] <a href="http://appdb.winehq.org/objectManager.php?sClass=version&amp;iId=25610&amp;iTestingId=70352">http://appdb.winehq.org/objectManager.php?sClass=version&amp;iId;=25610&amp;iTestingId;=70352</a></li>
  <li>[2] <a href="http://www.codeweavers.com/compatibility/browse/name/?forum=1;app_id=7714;mhl=130618;msg=130314">http://www.codeweavers.com/compatibility/browse/name/?forum=1;app_id=7714;mhl=130618;msg=130314</a></li>
</ul>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Setup a basic PHP development environment with Vagrant and chef-solo]]></title>
    <link href="http://lenss.nl/2012/08/setup-a-basic-php-development-environment-with-vagrant-and-chef-solo/"/>
    <updated>2012-08-27T00:47:05+02:00</updated>
    <id>http://lenss.nl/2012/08/setup-a-basic-php-development-environment-with-vagrant-and-chef-solo</id>
    <content type="html"><![CDATA[<p>So there are plenty of posts about this out there already. And this is nothing new i guess. But i am going to post it anyway. This weekend i spend some time playing with vagrant. And every setup guide seemed to be missing some steps the make the whole process a bit of a hassle. So i compiled my own steps in the post below. The goal was to create a basic <a href="http://www.debian.org/">Debian</a> box for my <a href="http://www.php.net/">PHP</a> development. From which i could serve my local development files.</p>

<p>So to start of we need some packages. </p>

<p><strong>Virtualbox</strong></p>

<p>To create the virtual development image</p>

<p><strong>NFS packages</strong></p>

<p>To make sharing files between host and guest easy as pie</p>

<p><strong>Vagrant</strong></p>

<p>To package the virtual image and manage newly created box</p>

<blockquote>
  <p>$ sudo apt-get install virtualbox vagrant nfs-common nfs-kernel-server</p>
</blockquote>

<p>Now is a good moment to download any Linux distro you want. I chose Debian. As it´s the most common in my day to day work.</p>

<blockquote>

  <p>$ wget <a href="http://cdimage.debian.org/debian-cd/6.0.5/i386/iso-cd/debian-6.0.5-i386-netinst.iso">http://cdimage.debian.org/debian-cd/6.0.5/i386/iso-cd/debian-6.0.5-i386-netinst.iso</a></p>
</blockquote>

<p>Now launch <a href="https://www.virtualbox.org/">virtualbox</a> and create a new virtual machine. Just do what you normally do when you create a VM. But make sure to choose VMDK `Virtual Machine Disk´ as the format. The rest should be ok. When the VM is created start it up and choose the freshly downloaded Linux ISO to start the installation.</p>

<p>I only installed the base system + the SSH server. And when that’s all done. And the VM is running. Login as root and install some packages vagrant needs.</p>

<blockquote>
  <p>$ apt-get install sudo ruby ruby-dev libopenssl-ruby rdoc ri irb build-essential ssl-cert curl rubygems puppet</p>
</blockquote>

<p>I won’t be setting up a <a href="http://www.opscode.com/chef/">Chef</a> server to manage the vagrant images. But i will be using <a href="http://wiki.opscode.com/display/chef/Installing+Chef+Client+and+Chef+Solo">Chef-Solo</a> to manage installing packages. So let’s install Chef.</p>

<p><strong>install chef</strong></p>

<p>Setup the opscode package repositories for APT</p>

<blockquote>

  <ul>
    <li>
      <table>
        <tbody>
          <tr>
            <td>$ echo “deb http://apt.opscode.com/ <code>lsb_release -cs</code>-0.10 main”</td>
            <td>tee /etc/apt/sources.list.d/opscode.list</td>
          </tr>
        </tbody>
      </table>
    </li>
    <li>$ gpg –keyserver keys.gnupg.net –recv-keys 83EF826A</li>
    <li>
      <table>
        <tbody>
          <tr>
            <td>$ gpg –export packages@opscode.com</td>
            <td>tee /etc/apt/trusted.gpg.d/opscode-keyring.gpg &gt; /dev/null</td>
          </tr>
        </tbody>
      </table>
    </li>
  </ul>
</blockquote>

<p>And finally install the opscode keymanager and and of course Chef.</p>

<blockquote>

  <ul>
    <li>$ apt-get update</li>
    <li>$ apt-get install opscode-keyring</li>
    <li>$ apt-get install chef</li>
  </ul>
</blockquote>

<p>The installer will ask for the chef URL. I used <strong>none</strong> because i will be using chef solo</p>

<p>Now we need to add a user for <a href="http://vagrantup.com/">vagrant</a> to connect with.</p>

<blockquote>

  <ul>
    <li>$ adduser vagrant </li>
    <li>passwrd : vagrant</li>
    <li>$ groupadd admin</li>
    <li>$ usermod -a -G admin vagrant</li>
  </ul>
</blockquote>

<p>Make sure the admin users can <strong>sudo</strong> without a password.</p>

<blockquote>

  <ul>
    <li>$ visudo</li>
    <li>%admin  ALL=(ALL) NOPASSWD: ALL</li>
  </ul>
</blockquote>

<p>Disable DNS for the SSH server. This should be a performance gain.</p>

<blockquote>

  <ul>
    <li>$ vi /etc/etc/ssh/sshd_config</li>
    <li>UseDNS no</li>
  </ul>
</blockquote>

<p>Change the MOTD to something nice</p>

<blockquote>
  <ul>
    <li>$ bash -c “echo ‘Sweeet! A Vagrant box cooked by Chef!!’ &gt; /etc/motd”</li>
    <li>$ chmod 0777 /etc/motd</li>
  </ul>
</blockquote>

<p>Switch to the vagrant user to setup the <strong>insecure</strong> vagrant public SSH key.</p>

<blockquote>
  <ul>
    <li>$ su vagrant</li>
    <li>mkdir -p ~/.ssh</li>
    <li>chmod 0700 ~/.ssh</li>
    <li>curl -o ~/.ssh/authorized_keys https://raw.github.com/mitchellh/vagrant/master/keys/vagrant.pub</li>
    <li>chmod 0600 ~/.ssh/authorized_keys </li>
  </ul>
</blockquote>

<p>That’s it for the VM. Now it’s time for vagrant to do some magic. First we need to create a vagrant package from the newly created VM.</p>

<blockquote>
  <ul>
    <li>$ vagrant package –base devbox</li>
    <li>$ mv package.box devbox.box</li>
  </ul>
</blockquote>

<p>Done! Let’s test it.</p>

<blockquote>
  <ul>
    <li>$ vagrant box add devbox devbox.box</li>
    <li>$ mkdir test &amp;&amp; cd test</li>
    <li>$ vagrant init devbox</li>
    <li>$ vagrant up</li>
    <li>$ vagrant ssh</li>
  </ul>
</blockquote>

<p>Voila ssh’d into the VM</p>

<blockquote>

  <ul>
    <li>$ exit</li>
    <li>$ vagrant halt</li>
    <li>$ vagrant destroy</li>
  </ul>
</blockquote>

<p>So that’s all fine and dandy. But a base system with SSH is not that useful. So that’s where Chef comes in. Like i mentioned earlier i won’t be using a Chef-Server. I will be using Chef-Solo. And will be doing a very basic setup.</p>

<p>A Chef install script is called a <a href="http://wiki.opscode.com/display/chef/Cookbooks">cookbook</a>. And they can be found all over the place. But the main repository is over here (find more here https://github.com/opscode/cookbooks). So in our vagrant folder we create a folder called cookbooks.</p>

<blockquote>
  <ul>
    <li>$ mkdir cookbooks</li>
    <li>$ cd cookbooks</li>
  </ul>
</blockquote>

<p>And we install some basic cookbooks. Plus a very simple one i hacked together to install the latest <a href="http://www.dotdeb.org/">dotdeb</a> package repositories.</p>

<p><a href="https://github.com/tlenss/misc/tree/master/chef/cookbooks/dotdeb">https://github.com/tlenss/misc/tree/master/chef/cookbooks/dotdeb</a></p>

<blockquote>

  <p>$ git clone <a href="https://github.com/opscode/cookbooks">https://github.com/opscode/cookbooks</a></p>
</blockquote>

<p>This will be enough for now. And will allow for some basic PHP development. To enable these package we have to edit the <strong>Vagrantfile</strong> file.</p>

<blockquote>
  <p>$ vi Vagrantfile</p>
</blockquote>

<p>Add these lines for apache forwarding and NFS sharing</p>

<blockquote>

  <p>config.vm.share_folder “www”, “/var/www”, “/dev/location”</p>
</blockquote>

<p>uncomment the :hostonly line so we can acces apache from our local box. And setup a hosts file mapping</p>

<blockquote>
  <ul>
    <li>config.vm.network :hostonly, “192.168.164.123”</li>
    <li>$ sudo sed -i ‘$ a\</li>
    <li>192.168.164.123	dev.box’ /etc/hosts</li>
  </ul>
</blockquote>

<p>Configure chef’s cookbook path and add some recipes from the cloned cookbooks.</p>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
config.vm.provision :chef_solo do |chef|
  chef.json = {
    &quot;mysql&quot; =&gt; {
      &quot;server_root_password&quot; =&gt; &quot;somepassword&quot;
      &quot;bind_address&quot; =&gt; &quot;127.0.0.1&quot;
    }
  }

  chef.cookbooks_path = &quot;cookbooks&quot;
  chef.add_recipe(&quot;dotdeb&quot;)
  chef.add_recipe(&quot;dotdeb::php54&quot;)
  chef.add_recipe(&quot;openssl&quot;)
  chef.add_recipe(&quot;apache2&quot;)
  chef.add_recipe(&quot;apache2::mod_php5&quot;)
  chef.add_recipe(&quot;apache2::mod_rewrite&quot;)
  chef.add_recipe(&quot;mysql&quot;)
  chef.add_recipe(&quot;mysql::server&quot;)
  chef.add_recipe(&quot;memcached&quot;)
  chef.add_recipe(&quot;vim&quot;)
  chef.add_recipe(&quot;php&quot;)
  chef.add_recipe(&quot;php::module_curl&quot;)
  chef.add_recipe(&quot;php::module_mysql&quot;)
  chef.add_recipe(&quot;php::module_memcache&quot;)
  chef.add_recipe(&quot;php::module_sqlite3&quot;)
end
</pre></div>
</div>
 </figure></notextile></div>

<p>Time to call vagrant again. And this time the startup takes a bit longer. All the selected packages get installed. And once that’s done. And a fresh development box is waiting.</p>

<blockquote>

  <ul>
    <li>$ vagrant up</li>
    <li>$ vagrant ssh</li>
  </ul>
</blockquote>

<p>Let’s check PHP</p>

<blockquote>
  <ul>
    <li>$ php -v</li>
    <li>PHP 5.4.6-1~dotdeb.0 (cli) (built: Aug 19 2012 08:45:58) </li>
    <li>Copyright (c) 1997-2012 The PHP Group</li>
    <li>Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies</li>
  </ul>
</blockquote>

<p>What about apache?</p>

<blockquote>
  <ul>
    <li>
      <table>
        <tbody>
          <tr>
            <td>$ ps -aux</td>
            <td>grep apache</td>
          </tr>
        </tbody>
      </table>
    </li>
    <li>root       790  0.1  0.2   5352  2580 ?        Ss   23:40   0:00 /usr/sbin/apache2 -k start</li>
    <li>www-data   793  0.0  0.1   5124  1764 ?        S    23:40   0:00 /usr/sbin/apache2 -k start</li>
    <li>www-data   797  0.0  0.2 546408  2412 ?        Sl   23:40   0:00 /usr/sbin/apache2 -k start</li>
    <li>www-data   798  0.0  0.2 546408  2404 ?        Sl   23:40   0:00 /usr/sbin/apache2 -k start</li>
    <li>www-data   811  0.0  0.2 546408  2424 ?        Sl   23:40   0:00 /usr/sbin/apache2 -k start</li>
  </ul>
</blockquote>

<p>Nice! And Pointing the browser to http://localhost:8080 loads the NFS shared folder up through Apache. That’s it for now. Time to sleep…</p>

<ul>
  <li>Some sources i used:</li>
  <li>[1] <a href="http://vagrantup.com/v1/docs/base_boxes.html">http://vagrantup.com/v1/docs/base_boxes.html</a></li>
  <li>[2] <a href="https://github.com/yevgenko/cookbook-dotdeb">https://github.com/yevgenko/cookbook-dotdeb</a></li>
  <li>[3] <a href="http://vagrantup.com/v1/docs/provisioners/chef_solo.html">http://vagrantup.com/v1/docs/provisioners/chef_solo.html</a></li>
</ul>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Adding colors to PHP CLI script output]]></title>
    <link href="http://lenss.nl/2012/05/adding-colors-to-php-cli-script-output/"/>
    <updated>2012-05-26T11:14:33+02:00</updated>
    <id>http://lenss.nl/2012/05/adding-colors-to-php-cli-script-output</id>
    <content type="html"><![CDATA[<p>I always loved writing CLI scripts. And in <a href="http://php.net/manual/en/features.commandline.php">PHP</a> this is no different. I write a lot of CLI importers, scrapers, reporters, etc. And sometimes i want a bit more funk in my output then the standard black and white. When output is important i will add some colors to make things more clear. And this is not hard at all.</p>

<p>First of it’s probably a good thing to gather some of the available colors. A good resource is available <a href="https://wiki.archlinux.org/index.php/Color_Bash_Prompt">here</a>. Some of the colors and their corresponding codes can be found below.</p>

<blockquote>

  <ul>
    <li>Black         0;30</li>
    <li>Blue          0;34</li>
    <li>Green         0;32</li>
    <li>Cyan          0;36</li>
    <li>Red           0;31</li>
    <li>Purple        0;35</li>
    <li>Brown         0;33</li>
    <li>Light Gray    0;37 </li>
    <li>Dark Gray     1;30</li>
    <li>Light Blue    1;34</li>
    <li>Light Green   1;32</li>
    <li>Light Cyan    1;36</li>
    <li>Light Red     1;31</li>
    <li>Light Purple  1;35</li>
    <li>Yellow        1;33</li>
    <li>White         1;37</li>
  </ul>
</blockquote>

<p>So how do i output colors you ask? Well that’s just plain easy. It’s a bit like setting up colors in your linux PS1 env variable.</p>

<p>Display a line in red for instance can be simply done by ‘echoing’ from the script with some extra formatting for bash to pickup. I will try to explain everything in the line below a bit later.</p>

<div class="bogus-wrapper"><notextile><figure class="code"> <div class="CodeRay">
  <div class="code"><pre>
    <span class="predefined">echo</span> <span class="string"><span class="delimiter">&quot;</span><span class="char">\033</span><span class="content">[31m some colored text </span><span class="char">\033</span><span class="content">[0m some white text </span><span class="char">\n</span><span class="delimiter">&quot;</span></span>;
    <span class="predefined">echo</span> <span class="string"><span class="delimiter">&quot;</span><span class="char">\033</span><span class="content">[32m some colored text </span><span class="char">\033</span><span class="content">[0m some white text </span><span class="char">\n</span><span class="delimiter">&quot;</span></span>;
</pre></div>
</div>
 </figure></notextile></div>

<p>So what’s going on here. First we use an escape character so we can actually define a output color. This is done with <strong>\033</strong> (\e). Then we open the color statement with <strong>[31m</strong>. Red in this case. The “some colored text” will be the text outputted in a different color. And after that we have to close the color statement with <strong>\033[0m</strong>.</p>

<p>Easy as cake… that’s all!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[abbywinters is looking for new developers]]></title>
    <link href="http://lenss.nl/2012/05/abbywinters-is-looking-for-new-developers/"/>
    <updated>2012-05-24T15:04:02+02:00</updated>
    <id>http://lenss.nl/2012/05/abbywinters-is-looking-for-new-developers</id>
    <content type="html"><![CDATA[<p><img class="left" src="http://lenss.nl/images/2011/11/aw-logo-roundel-blue.png" />
If you’re looking for a new challenging and exiting Senior Webdeveloper position. Don’t look any further. If you already think you have the job of your dreams. Think again!</p>

<p><em><a href="http://www.abbywinters.com">abbywinters.com</a> <strong>(NSFW)</strong> is one of the largest and most ethical, highly rated, well designed, and successful erotic websites in the world today. abbywinters.com is the WINNER of the AVN 2011 Awards for Best Membership site!</em></p>

<p>And we are looking to hire a new talented webdeveloper to expand our small team. What would you think about joining our small Agile team of highly qualified professionals? </p>

<p>You will be creating sexy, exiting and game changing experiences for the web, work for one of the industry leaders. And just be part of an awesome company. Some of the jobs key elements are:</p>

<ul>
  <li>
    <p>Implementing development projects</p>
  </li>
  <li>
    <p>Leading informal mentoring during day-to-day work</p>
  </li>
  <li>
    <p>Contribute to design of development projects</p>
  </li>
  <li>
    <p>Track, reduce, and prevent technical debt in Web Development projects</p>
  </li>
</ul>

<blockquote>
  <p>Motivated by principles of social responsibility, we deliver provocative media by embracing imagination, creativity and emerging technologies. Our models, customers and business partners are inspired by our fervid passion.</p>

</blockquote>

<blockquote>

  <p>Our experienced staff use state-of-the-art content production facilities to produce 10 shoots a week from concept to finished art, utilizing the most advanced digital capture, post production and delivery systems in the world.</p>

</blockquote>

<blockquote>

  <p>You will be working directly with our Web Dev Manager, Lead developer and colleagues in the web dev team. We need each individual to contribute for us to continue as a pioneer in our industry.</p>
</blockquote>

<p>If you posses a “Can do” attitude. Would like to work in the center of Amsterdam. And are able to identify your self in the criteria below. You might want to head over to our <a href="http://careers.abbywinters.com/job-opportunities/senior-php-developer/">career portal</a> for a more detailed description.  </p>

<p><strong>Technical competencies – Required</strong></p>

<ul>
  <li>
    <p>High level of skill with PHP 5</p>
  </li>
  <li>
    <p>High level of skill with Object Oriented Programming</p>
  </li>
  <li>
    <p>High level of skill with HTML/CSS</p>
  </li>
  <li>
    <p>High level of skill with JavaScript</p>
  </li>
  <li>
    <p>High level of skill with Internet Applications</p>
  </li>
  <li>
    <p>Moderate level of skill with Unit Testing and Test Driven Design</p>
  </li>
  <li>
    <p>Moderate level of skill with MySQL</p>
  </li>
  <li>
    <p>Moderate level of skill with Windows XP operating system</p>
  </li>
  <li>
    <p>Experience with the GNU/Linux operating system</p>
  </li>
  <li>
    <p>Competent with Revision Control systems (Subversion)</p>
  </li>
  <li>
    <p>Bachelor of Science in Computer Science, or equivalent experience</p>
  </li>
  <li>
    <p>Zend Certified Engineer, or equivalent experience</p>
  </li>
  <li>
    <p>At least 5 years experience in Web Application Development</p>
  </li>
</ul>

<p><strong>Technical competencies – Desired</strong></p>

<ul>
  <li>
    <p>Moderate level of skill with the Apache HTTP server</p>
  </li>
  <li>
    <p>Good understanding of the Model-View-Controller pattern</p>
  </li>
  <li>
    <p>Good understanding of the ActiveRecord Object-Relational-Mapping pattern</p>
  </li>
  <li>
    <p>Familiarity with Agile software development practices (Scrum)</p>
  </li>
  <li>
    <p>E-commerce</p>
  </li>
  <li>
    <p>Agile development experience</p>
  </li>
</ul>

]]></content>
  </entry>
  
</feed>
