<?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>le blog &#187; PHP</title>
	<atom:link href="http://www.normyee.net/blog/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.normyee.net/blog</link>
	<description></description>
	<lastBuildDate>Fri, 03 Feb 2012 20:51:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>CloudFlare, Apache, WordPress and IP address logging</title>
		<link>http://www.normyee.net/blog/2011/10/06/cloudflare-apache-wordpress-and-ip-address-logging/</link>
		<comments>http://www.normyee.net/blog/2011/10/06/cloudflare-apache-wordpress-and-ip-address-logging/#comments</comments>
		<pubDate>Fri, 07 Oct 2011 06:53:40 +0000</pubDate>
		<dc:creator>norm</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[webdev]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[cloudflare]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.normyee.net/blog/?p=299</guid>
		<description><![CDATA[If like me, you use the very useful CloudFlare service to speed up &#38; protect your site(s), you may have noticed that since using CloudFlare, your access logs may seem to have a ton of visits from a very narrow range of IP addresses. This is because CloudFlare acts as a reverse proxy and the IPs [...]]]></description>
			<content:encoded><![CDATA[<p>If like me, you use the very useful <a href="http://cloudflare.com" target="_blank">CloudFlare</a> service to speed up &amp; protect your site(s), you may have noticed that since using CloudFlare, your access logs may seem to have a ton of visits from a very narrow range of IP addresses. This is because CloudFlare acts as a <a href="http://en.wikipedia.org/wiki/Reverse_proxy" target="_blank">reverse proxy</a> and the IPs you are seeing are from CloudFlare&#8217;s network.</p>
<p>This is a bit sucky for analytics since those IPs are not of the actual visitors to your site(s). The original IP is still in the HTTP request headers when CloudFlare is enabled, though, and looks something like this sample request header:</p>
<pre class="brush: bash; highlight: [4]; title: ; notranslate">
GET /blog/feed/ HTTP/1.0
Host: www.normyee.net
Accept-Encoding: gzip
CF-Connecting-IP: 66.249.71.111
CF-IPCountry: US
X-Forwarded-For: 66.249.71.111
Connection: close
Set-Keepalive: 0
Accept: */*
From: googlebot(at)googlebot.com
User-Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)
</pre>
<p>CloudFlare inserts a <code>CF-Connecting-IP</code> header containing the original requester&#8217;s IP. In this case, the IP 66.249.71.111 is google&#8217;s web crawler paying me a visit, although the request was logged as coming from 199.27.128.71 &#8212; one of CloudFlare&#8217;s IPs. We of course want the original IP logged, and not CloudFlare&#8217;s. Fortunately there are quick solutions for both Apache and WordPress.</p>
<p>For Apache, CloudFlare has an Apache module, mod_cloudflare, which you&#8217;ll need to compile from source for your system. You can get more info and instructions <a href="http://www.cloudflare.com/wiki/Log_Files" target="_blank">here</a> &amp; view <a href="https://github.com/cloudflare/CloudFlare-Tools/blob/master/mod_cloudflare.c" target="_blank">the source on github here</a> (it&#8217;s linked to from the previous link as well). It&#8217;s pretty straightforward, assuming you have shell access and the ability to run apxs (the <a href="http://httpd.apache.org/docs/2.2/programs/apxs.html" target="_blank">APache eXtenSion tool</a>).</p>
<p>For WordPress, you can just simply download the <a href="http://wordpress.org/extend/plugins/cloudflare/" target="_blank">CloudFlare WordPress plugin at wordpress.org</a> to get the correct IPs back in WordPress. CloudFlare has a <a href="http://www.cloudflare.com/wiki/CloudFlareWordPressPlugin" target="_blank">wiki page for the plugin</a> as well, but the WordPress.org plugin page has all the info you need.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.normyee.net/blog/2011/10/06/cloudflare-apache-wordpress-and-ip-address-logging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updating WordPress via SSH instead of FTP</title>
		<link>http://www.normyee.net/blog/2009/12/01/updating-wordpress-via-ssh-instead-of-ftp/</link>
		<comments>http://www.normyee.net/blog/2009/12/01/updating-wordpress-via-ssh-instead-of-ftp/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 19:09:54 +0000</pubDate>
		<dc:creator>norm</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.normyee.net/blog/?p=120</guid>
		<description><![CDATA[I&#8217;ve shut off FTP access to my server a while back, since FTP passwords are passed in plaintext over the net which is A Bad Thing™. For the occasions that I would need to update WordPress via its web interface, I would start up the FTP daemon so that I could use WordPress&#8217; auto-update feature, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve shut off FTP access to my server a while back, since FTP passwords are <a href="http://en.wikipedia.org/wiki/Ftp#Security_problems" target="_blank">passed in plaintext over the net</a> which is A Bad Thing™. For the occasions that I would need to update WordPress via its web interface, I would start up the FTP <a href="http://en.wikipedia.org/wiki/Daemon_%28computer_software%29" target="_blank">daemon</a> so that I could use WordPress&#8217; auto-update feature, and then shut it back down after I was done. Not that big of a hassle, but it required me to login into my server before doing anything from the web interface which was one step too many.</p>
<p>I discovered that WordPress has built-in support for <a href="http://codex.wordpress.org/Editing_wp-config.php#FTP.2FSSH_Constants" target="_blank">updating via SSH2</a> if PHP has the <a href="http://en.wikipedia.org/wiki/PHP_Extension_Community_Library#PECL" target="_blank">PECL</a> <a href="http://pecl.php.net/package/ssh2" target="_blank">SSH2 library</a> installed. Following is a quick summary of how to get it running.</p>
<p>The PECL ssh2 library requires <a href="http://www.sourceforge.net/projects/libssh2" target="_blank">libssh2</a> which I downloaded and then compiled painlessly with a</p>
<pre class="brush: bash; gutter: true; title: ; toolbar: false; notranslate">$ ./configure
$ make
$ make install</pre>
<p>Once libssh2 was compiled and installed, I installed the PECL ssh2 library via</p>
<pre class="brush: bash; gutter: true; title: ; toolbar: false; notranslate">$ pecl install -f ssh2</pre>
<p>The -f flag is to force the install since ssh2 is still in beta &amp; you&#8217;d otherwise get a warning like</p>
<pre class="brush: plain; auto-links: false; light: true; title: ; notranslate">Failed to download pecl/ssh2 within preferred state &quot;stable&quot;, latest release is version 0.11.0, stability &quot;beta&quot;, use &quot;channel://pecl.php.net/ssh2-0.11.0&quot; to install</pre>
<p>After installing ssh2 via pecl, i edited the php.ini file (located at /etc/php.ini for me) to tell PHP to load this extension</p>
<pre class="brush: bash; gutter: true; title: ; toolbar: false; notranslate">extension=ssh2.so</pre>
<p>and then restart apache afterwards (via <code>apachctl</code>, <code>service httpd restart</code>, or whatever is appropriate for your system) so that the library would be available to PHP.</p>
<p>After apache comes back up, you should see a new option (SSH) in the wordpress upgrade page (which applies to plugins as well).</p>
<p>BTW, if you&#8217;re on a Red Hat Fedora system and/or use <a href="http://en.wikipedia.org/wiki/Yellowdog_Updater,_Modified" target="_blank">yum</a>, you might be able to just pull the libssh2 rpm from yum instead of compiling it:</p>
<pre class="brush: bash; gutter: true; title: ; toolbar: false; notranslate">$ yum install libssh2
$ yum install libssh2-devel
$ yum install libssh2-docs</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.normyee.net/blog/2009/12/01/updating-wordpress-via-ssh-instead-of-ftp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ZendCon 2007 Day 1</title>
		<link>http://www.normyee.net/blog/2007/10/10/zendcon-2007-day-1/</link>
		<comments>http://www.normyee.net/blog/2007/10/10/zendcon-2007-day-1/#comments</comments>
		<pubDate>Wed, 10 Oct 2007 07:39:47 +0000</pubDate>
		<dc:creator>norm</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.normyee.net/blog/2007/10/10/zendcon-2007-day-1/</guid>
		<description><![CDATA[was not too bad. I went to 5 sessions and found at least 2 of them moderately helpful, namely Ben Ramsey&#8217;s session on memcached and Eli White&#8217;s PHP &#38; MySQL scaling techniques. I might put up a short list of take aways in a few days. View from the back]]></description>
			<content:encoded><![CDATA[<p>was not too bad. I went to 5 sessions and found at least 2 of them moderately helpful, namely Ben Ramsey&#8217;s session on <a href="http://danga.com/memcached/" target="_blank">memcached</a> and Eli White&#8217;s PHP &amp; MySQL scaling techniques. I might put up a short list of take aways in a few days.</p>
<p><a href="http://www.normyee.net/blog/?attachment_id=49" rel="attachment wp-att-49" title="View from the back">View from the back</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.normyee.net/blog/2007/10/10/zendcon-2007-day-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP&#8217;s curl_multi to the rescue</title>
		<link>http://www.normyee.net/blog/2007/09/11/curl_multi-to-the-rescue/</link>
		<comments>http://www.normyee.net/blog/2007/09/11/curl_multi-to-the-rescue/#comments</comments>
		<pubDate>Tue, 11 Sep 2007 23:48:18 +0000</pubDate>
		<dc:creator>norm</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[webdev]]></category>

		<guid isPermaLink="false">http://www.normyee.net/blog/2007/09/11/curl_multi-to-the-rescue/</guid>
		<description><![CDATA[One of my Facebook apps hits Amazon&#8217;s Ecommerce Service (ECS) for item information via REST queries. I needed to process 19 separate queries searching for a title (basically searching 1 of 19 &#8220;browse nodes&#8221;), and return that data onto the Facebook canvas. Simple enough, I could just do a foreach loop to make each REST [...]]]></description>
			<content:encoded><![CDATA[<p>One of my <a href="http://apps.facebook.com/gamersnetwork/" target="_blank">Facebook apps</a> hits <a href="http://www.amazon.com/E-Commerce-Service-AWS-home-page/b/ref=sc_fe_l_2/104-9762278-8592743?ie=UTF8&amp;node=12738641&amp;no=342430011&amp;me=A36L942TSJ2AJA" target="_blank">Amazon&#8217;s Ecommerce Service (ECS)</a> for item information via <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer" target="_blank">REST</a> queries. I needed to process 19 separate queries searching for a title (basically searching 1 of 19 &#8220;browse nodes&#8221;), and return that data onto the Facebook canvas.</p>
<p>Simple enough, I could just do a foreach loop to make each REST request. Only problem was, say, each loop took 500 milliseconds total. That&#8217;s not hard when you consider all the steps: DNS, performing the REST query, waiting for the response, receiving the response, and then parsing the XML (in this case, using the <a href="http://us.php.net/simplexml" target="_blank">SimpleXML extension</a>). At 19 requests that&#8217;s 9.5 seconds which is way too slow, not to mention Facebook times out the request as well and returns a lovely error page.</p>
<p>For the test REST query I was benchmarking, it was averaging 9.65 seconds for the entire PHP script to complete (performing all 19 REST queries and then formatting the output). Simply switching from <a href="http://us.php.net/file_get_contents" target="_blank">file_get_contents()</a> to PHP&#8217;s <a href="http://us.php.net/curl" target="_blank">cURL functions</a> dropped the average to 7.32 seconds, a roughly 24% improvement. That was a great improvement, but still too slow and Facebook was still timing out the pages.</p>
<p>The root of the problem was that the 19 REST queries were <strong>sequential</strong> and as a result too slow. I needed to make those requests <strong>concurrently</strong>. Fortunately, PHP supported multi curl (basically making multiple cURL requests concurrently) via curl_multi_* functions.</p>
<p>BAM.  Using curl_multi dropped the page generation time down to 1.6 seconds &#8212; much more reasonable and a 83.4% improvement. w00t.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.normyee.net/blog/2007/09/11/curl_multi-to-the-rescue/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using apc
Object Caching 641/682 objects using apc

Served from: www.normyee.net @ 2012-02-05 10:26:40 -->
