<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rusty Razor Blade &#187; php</title>
	<atom:link href="http://www.rustyrazorblade.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rustyrazorblade.com</link>
	<description>Tech Thoughts, Mostly on LAMP - by Jon Haddad</description>
	<lastBuildDate>Wed, 21 Jul 2010 20:42:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>UIS PHP53, DOM Parsing, PHPUnit, Puppet Config Solution</title>
		<link>http://www.rustyrazorblade.com/2010/07/uis-php53-dom-parsing-phpunit-puppet-config-solution/</link>
		<comments>http://www.rustyrazorblade.com/2010/07/uis-php53-dom-parsing-phpunit-puppet-config-solution/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 20:42:03 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[puppet]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/?p=1126</guid>
		<description><![CDATA[I&#8217;m using PHP53 package from the IUS Community repository.  I&#8217;ve been trying to get phpunit to install, but it gives an error that it needs DOM install.  It took me a little bit to figure this out, but I finally got it working.  What you need is the php53-xml package.  You [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m using PHP53 package from the <a href="http://iuscommunity.org/">IUS Community</a> repository.  I&#8217;ve been trying to get phpunit to install, but it gives an error that it needs DOM install.  It took me a little bit to figure this out, but I finally got it working.  What you need is the php53-xml package.  You can install it using </p>
<pre>
yum install php53-xml
</pre>
<p>or if you&#8217;re using puppet</p>
<pre>
package { ["php53-xml"]:
          ensure => present
        }
</pre>
<p>And finally, to get it to install, I used the below.   I had to make it go to multiple lines to fit on the page but I have it all on 1 line in my puppet script:</p>
<pre>
exec { "pear channel-discover pear.phpunit.de;
pear channel-discover pear.symfony-project.com;
pear install --alldeps phpunit/PHPUnit  ":
          creates => "/usr/bin/phpunit"
 }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2010/07/uis-php53-dom-parsing-phpunit-puppet-config-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with DOM in PHP &#8211; Looking at a PHP HTML Parser</title>
		<link>http://www.rustyrazorblade.com/2010/06/working-with-dom-in-php-looking-at-an-html-parser/</link>
		<comments>http://www.rustyrazorblade.com/2010/06/working-with-dom-in-php-looking-at-an-html-parser/#comments</comments>
		<pubDate>Sun, 06 Jun 2010 19:25:45 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/?p=1095</guid>
		<description><![CDATA[So, lets assume you&#8217;ve got a PHP project where you&#8217;re scraping pages and trying parse fields out of the DOM.  Up till now, I&#8217;ve just used regular expressions because they&#8217;re easy.  I avoided trying to parse html as xml using SimpleXML because there&#8217;s just to many cases where it would fail due to invalid tags.
Well, [...]]]></description>
			<content:encoded><![CDATA[<p>So, lets assume you&#8217;ve got a PHP project where you&#8217;re scraping pages and trying parse fields out of the DOM.  Up till now, I&#8217;ve just used regular expressions because they&#8217;re easy.  I avoided trying to parse html as xml using SimpleXML because there&#8217;s just to many cases where it would fail due to invalid tags.</p>
<p>Well, I feel like an idiot.  It turns out there&#8217;s a great extension built into PHP to do just that, and it&#8217;s the <a href="http://us.php.net/manual/en/book.dom.php">DOM extension</a>.  Using this, parsing HTML with PHP is just as easy as accessing the DOM using <a href="http://jquery.com/">JQuery</a>. (hint: very easy).</p>
<p>Lets say we&#8217;ve got a page our drive already.  For this example, I&#8217;ll use the <a href="http://www.rustyrazorblade.com/">homepage of this blog</a>.  We&#8217;re going to parse out all the links.  I&#8217;ve saved the page as index.html and in the same directory I&#8217;ve created the parser script.</p>
<pre>&lt;?
$dom = new DomDocument;</pre>
<pre>// you can use loadHTML if you already have your string in memory
$dom-&gt;loadHTMLFile( "index.html" );
$dom-&gt;preserveWhiteSpace = false;

// grab all the A tags
// returns a domnodelist
$tags = $dom-&gt;getElementsByTagName( 'a' );

// you can actually iterate over the tags returned - </pre>
<pre>// I'm not sure why they don't say that more explicitly
</pre>
<pre>echo "Total length:"  . count($tags-&gt;length) . "\n";

foreach($tags as $t)
{
	// each of these is a DOMElement object
	// the value is what's inside the tag
	// the attributes can also be accessed
	printf( "%-50s%s   \n", $t-&gt;nodeValue, $t-&gt;getAttribute('href') );

}</pre>
<p>Here&#8217;s a glimpse of the output:</p>
<pre>
vim                 http://www.rustyrazorblade.com/category/vim/  
virtual box         http://www.rustyrazorblade.com/category/virtual-box/   
vmware              http://www.rustyrazorblade.com/category/vmware/
weird               http://www.rustyrazorblade.com/category/weird/   
wikipedia           http://www.rustyrazorblade.com/category/wikipedia/
windows             http://www.rustyrazorblade.com/category/windows/  
xcode               http://www.rustyrazorblade.com/category/xcode/ 
﻿</pre>
</p>
<p><a target="_blank" href="http://www.phpro.org/examples/Parse-HTML-With-PHP-And-DOM.html">Here&#8217;s another great reference</a> I originally used to get started:</p>
<p>You can take this a bit further if you want to use the <a href="http://php.net/manual/en/book.curl.php">php curl extension</a>.  Additionally, if you&#8217;re interested in using the advanced curl_multi_exec functionality, check out my <a href="2008/02/curl_multi_exec/" target="_blank">previous post</a>.</p>
<p><em>Edit: <a href="http://www.reddit.com/user/cynope">cynope</a> on reddit suggested <a href="http://code.google.com/p/phpquery/">phpquery</a>.  I haven&#8217;t used it yet but it looks pretty cool. If I get a chance to try it I&#8217;ll post a followup.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2010/06/working-with-dom-in-php-looking-at-an-html-parser/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Geek Links</title>
		<link>http://www.rustyrazorblade.com/2009/04/geek-links/</link>
		<comments>http://www.rustyrazorblade.com/2009/04/geek-links/#comments</comments>
		<pubDate>Thu, 23 Apr 2009 22:25:11 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[apple]]></category>
		<category><![CDATA[links]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/?p=652</guid>
		<description><![CDATA[
PHP Quick Profiler

This looks like a pretty cool tool to get a good idea of what&#8217;s going on in your PHP script without having to install tools like XDebug and Webgrind / KCacheGrind.
Apple files patent for browser specific volume
I&#8217;m not sure how this is anything new, tons of applications have their own volume setting.  [...]]]></description>
			<content:encoded><![CDATA[<ul>
<li><a href="http://particletree.com/features/php-quick-profiler/">PHP Quick Profiler</a>
</li>
<p>This looks like a pretty cool tool to get a good idea of what&#8217;s going on in your PHP script without having to install tools like XDebug and <a href="http://code.google.com/p/webgrind/">Webgrind </a>/ <a href="http://kcachegrind.sourceforge.net/html/Home.html">KCacheGrind</a>.</p>
<li><a href="http://www.theregister.co.uk/2009/04/23/browser_silencer/">Apple files patent for browser specific volume</a></li>
<p>I&#8217;m not sure how this is anything new, tons of applications have their own volume setting.  Quicktime, VLC, Windows Media Player.  </p>
<li><a href="http://www.theregister.co.uk/2009/04/23/myspace_ceo_steps_down/">Chris DeWolfe bails as MySpace CEO</a></li>
<p>Doesn&#8217;t seem like such a bad idea to get out now.  It&#8217;s essentially just a giant ad for Fox TV shows and movies.  </p>
<li><a href="http://joeldowns.com/2009/04/23/tivo-add-an-app-store-now/">Tivo App Store</a></li>
<p>Joel Downs believes Tivo should open an app store.  I suppose if they are going to continue with their business model, it would make sense, since it probably won&#8217;t be long till the Xbox has Tivo functionality.  It might already, but I wouldn&#8217;t know.</p>
<li><a href="http://www.techcrunch.com/2009/04/23/apples-app-store-1-billion-served/">App store hits 1 billion downloads</a></li>
<p>Speaking of an App store, Apple seems to be doing OK.  The sad thing is I still haven&#8217;t thought of an interesting app to write.
</ul>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2009/04/geek-links/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quickly Check every PHP file in your project for errors</title>
		<link>http://www.rustyrazorblade.com/2008/12/quickly-check-every-php-file-in-your-project-for-errors/</link>
		<comments>http://www.rustyrazorblade.com/2008/12/quickly-check-every-php-file-in-your-project-for-errors/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 19:28:29 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/?p=438</guid>
		<description><![CDATA[Here&#8217;s a quickie &#8211; make sure every PHP file in your project parses correctly.
find . -name &#8216;*.php&#8217; -exec php -l {} \; &#124; grep &#8220;Errors parsing&#8221;
]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quickie &#8211; make sure every PHP file in your project parses correctly.</p>
<p>find . -name &#8216;*.php&#8217; -exec php -l {} \; | grep &#8220;Errors parsing&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2008/12/quickly-check-every-php-file-in-your-project-for-errors/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>VMWare, Losing Time, and Sessions</title>
		<link>http://www.rustyrazorblade.com/2008/05/vmware-losing-time-and-sessions/</link>
		<comments>http://www.rustyrazorblade.com/2008/05/vmware-losing-time-and-sessions/#comments</comments>
		<pubDate>Thu, 08 May 2008 18:37:43 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[vmware]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/?p=124</guid>
		<description><![CDATA[I&#8217;ll keep it short.  In the last few days, login on our dev server broke.  We hadn&#8217;t changed anything related to it, and everything looked good code wise.  What we finally figured out was that our session cookie was set to expire 2 days into the future, and our VMWare image had [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll keep it short.  In the last few days, login on our dev server broke.  We hadn&#8217;t changed anything related to it, and everything looked good code wise.  What we finally figured out was that our session cookie was set to expire 2 days into the future, and our VMWare image had lost 2 days of time.  </p>
<p>Fix by doing the following:</p>
<blockquote><p>ntpdate ntp.nasa.gov > /dev/null</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2008/05/vmware-losing-time-and-sessions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP Warning: Memcache::set(): Failed to extract &#8216;connection&#8217; variable</title>
		<link>http://www.rustyrazorblade.com/2008/04/php-warning-memcacheset-failed-to-extract-connection-variable/</link>
		<comments>http://www.rustyrazorblade.com/2008/04/php-warning-memcacheset-failed-to-extract-connection-variable/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 01:46:15 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[memcached]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/?p=119</guid>
		<description><![CDATA[I got this today.  Solved by restarting the Memcached server.  Move along.
Edit: this is actually a reoccurring bug we&#8217;re seeing with the memcache 2.2.3 stable build on 2 different boxes
2nd Edit: Actually it was a bug in my code.  I wasn&#8217;t setting the server and ip correctly, there was a typo in [...]]]></description>
			<content:encoded><![CDATA[<p>I got this today.  Solved by restarting the Memcached server.  Move along.</p>
<p><em>Edit: this is actually a reoccurring bug we&#8217;re seeing with the memcache 2.2.3 stable build on 2 different boxes</em><br />
<em>2nd Edit: Actually it was a bug in my code.  I wasn&#8217;t setting the server and ip correctly, there was a typo in my configuration</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2008/04/php-warning-memcacheset-failed-to-extract-connection-variable/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How curl_exec and urlencode killed my single sign on</title>
		<link>http://www.rustyrazorblade.com/2008/04/how-curl_exec-and-urlencode-killed-my-single-sign-on/</link>
		<comments>http://www.rustyrazorblade.com/2008/04/how-curl_exec-and-urlencode-killed-my-single-sign-on/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 18:02:04 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[curl]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/?p=117</guid>
		<description><![CDATA[If you do any work with single sign on, you&#8217;ll be familiar with the concept of exchanging tokens and validating against the authentication server using that token.  One of the issues I&#8217;ve just run into which resulted in a huge headache is with urlencoding the result of a curl_exec that had a line ending. [...]]]></description>
			<content:encoded><![CDATA[<p>If you do any work with single sign on, you&#8217;ll be familiar with the concept of exchanging tokens and validating against the authentication server using that token.  One of the issues I&#8217;ve just run into which resulted in a huge headache is with urlencoding the result of a curl_exec that had a line ending. It&#8217; easy to miss when it&#8217;s a longer string and you aren&#8217;t paying very close attention.  This is a very simple example, and it still takes a second to realize there&#8217;s an extra character at the end.</p>
<blockquote><p>php> echo urlencode(&#8221;test@str!ngw!th0u7\n&#8221;);<br />
test%40str%21ngw%21th0u7%0A<br />
php> echo urlencode(&#8221;test@str!ngw!th0u7&#8243;);<br />
test%40str%21ngw%21th0u7</p></blockquote>
<p>Basically, I&#8217;d recommend calling a trim() on any results you get back, unless you love newlines at the end for some reason.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2008/04/how-curl_exec-and-urlencode-killed-my-single-sign-on/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Executing multiple curl requests in parallel with PHP and curl_multi_exec</title>
		<link>http://www.rustyrazorblade.com/2008/02/curl_multi_exec/</link>
		<comments>http://www.rustyrazorblade.com/2008/02/curl_multi_exec/#comments</comments>
		<pubDate>Thu, 21 Feb 2008 00:17:24 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[curl]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/2008/02/20/executing-multiple-curl-requests-in-parallel-with-php-and-curl_multi_exec/</guid>
		<description><![CDATA[Let&#8217;s get one thing out in the open. Curl is sweet.  It does it&#8217;s job very well, and I&#8217;m absoutely thrilled it exists.
If you&#8217;re using curl in your PHP app to make web requests, you&#8217;ve probably realized that by doing them one after the other, the total time of your request is the sum [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s get one thing out in the open. Curl is sweet.  It does it&#8217;s job very well, and I&#8217;m absoutely thrilled it exists.</p>
<p>If you&#8217;re using curl in your PHP app to make web requests, you&#8217;ve probably realized that by doing them one after the other, the total time of your request is the sum of all the requests put together.  That&#8217;s lame.</p>
<p>Unfortunately using the curl_multi_exec is poorly documented in the PHP manual.</p>
<p>Let&#8217;s say that your app is hitting APIs from these servers:</p>
<p>Google: .1s<br />
Microsoft: .3s<br />
rustyrazorblade.com: .5s</p>
<p>Your total time will be .9s, just for api calls.  </p>
<p>By using curl_multi_exec, you can execute those requests in parallel, and you&#8217;ll only be limited by the slowest request, which is about .5 sec to rustyrazorblade in this case, assuming your download bandwidth is not slowing you down.</p>
<p>Sample code:</p>
<pre>
$nodes = array('http://www.google.com', 'http://www.microsoft.com', 'http://www.rustyrazorblade.com');
$node_count = count($nodes);

$curl_arr = array();
$master = curl_multi_init();

for($i = 0; $i &lt; $node_count; $i++)
{
	$url =$nodes[$i];
	$curl_arr[$i] = curl_init($url);
	curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, true);
	curl_multi_add_handle($master, $curl_arr[$i]);
}

do {
    curl_multi_exec($master,$running);
} while($running &gt; 0);

echo &quot;results: &quot;;
for($i = 0; $i &lt; $node_count; $i++)
{
	$results = curl_multi_getcontent  ( $curl_arr[$i]  );
	echo( $i . &quot;\n&quot; . $results . &quot;\n&quot;);
}
echo 'done';</pre>
<p>It&#8217;s really not documented on php.net how to use curl_multi_getcontent, so hopefully this helps someone.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2008/02/curl_multi_exec/feed/</wfw:commentRss>
		<slash:comments>62</slash:comments>
		</item>
		<item>
		<title>Getting phpsh to work on a mac</title>
		<link>http://www.rustyrazorblade.com/2007/12/getting-phpsh-to-work-on-a-mac/</link>
		<comments>http://www.rustyrazorblade.com/2007/12/getting-phpsh-to-work-on-a-mac/#comments</comments>
		<pubDate>Tue, 18 Dec 2007 18:14:09 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/index.php/2007/12/18/getting-phpsh-to-work-on-a-mac/</guid>
		<description><![CDATA[I had an issue getting phpsh to work on my mac &#8211; I kept getting the following error:
Traceback (most recent call last):
  File &#8220;./phpsh&#8221;, line 20, in 
    import readline
OK, seems easy enough.  So I compiled python with readline support.
./configure &#8211;prefix=/usr/local/python &#8211;enable-readline 
I change the PATH variable in my .bash_profile [...]]]></description>
			<content:encoded><![CDATA[<p>I had an issue getting phpsh to work on my mac &#8211; I kept getting the following error:</p>
<blockquote><p>Traceback (most recent call last):<br />
  File &#8220;./phpsh&#8221;, line 20, in <module><br />
    import readline</p></blockquote>
<p>OK, seems easy enough.  So I compiled python with readline support.</p>
<blockquote><p>./configure &#8211;prefix=/usr/local/python &#8211;enable-readline </p></blockquote>
<p>I change the PATH variable in my .bash_profile to point to the /usr/local/python directory first, and source&#8217;d it to get the new PATH settings.  Still get the same error.</p>
<p>Usually at this point I&#8217;d like to tell you what was wrong, and how I fixed it.  But you know what &#8211; I never figured it out.  I just installed the python binary from python.org.  And it works.</p>
<p>Sometimes it&#8217;s just not worth fighting the battle.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2007/12/getting-phpsh-to-work-on-a-mac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ob_start() causes phpsh to hang, sort of</title>
		<link>http://www.rustyrazorblade.com/2007/12/ob_start-causes-phpsh-to-hang-sort-of/</link>
		<comments>http://www.rustyrazorblade.com/2007/12/ob_start-causes-phpsh-to-hang-sort-of/#comments</comments>
		<pubDate>Sat, 15 Dec 2007 22:19:09 +0000</pubDate>
		<dc:creator>jon</dc:creator>
				<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://www.rustyrazorblade.com/index.php/2007/12/15/ob_start-causes-phpsh-to-hang-sort-of/</guid>
		<description><![CDATA[If you manually call ob_start() at the beginning of your script, you might notice that you are unable to use phpsh.  By commenting it out, I was able to fix the issue.
I don&#8217;t think it technically hangs, it just sits there with the data in a buffer waiting to be flushed.  
]]></description>
			<content:encoded><![CDATA[<p>If you manually call ob_start() at the beginning of your script, you might notice that you are unable to use phpsh.  By commenting it out, I was able to fix the issue.</p>
<p>I don&#8217;t think it technically hangs, it just sits there with the data in a buffer waiting to be flushed.  </p>
]]></content:encoded>
			<wfw:commentRss>http://www.rustyrazorblade.com/2007/12/ob_start-causes-phpsh-to-hang-sort-of/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
