<?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>Building the Web &#187; php</title>
	<atom:link href="http://www.filonov.com/blog/tags/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.filonov.com/blog</link>
	<description>Web development notes, tips, tricks, ideas, thoughts</description>
	<lastBuildDate>Fri, 04 Mar 2011 15:43:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Nightmare of PHP programmer: include_once fails</title>
		<link>http://www.filonov.com/blog/2011/03/04/nightmare-of-php-programmer-include_once-fails/</link>
		<comments>http://www.filonov.com/blog/2011/03/04/nightmare-of-php-programmer-include_once-fails/#comments</comments>
		<pubDate>Fri, 04 Mar 2011 15:43:16 +0000</pubDate>
		<dc:creator>Andrei Filonov</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[troubleshooting]]></category>
		<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://www.filonov.com/blog/?p=63</guid>
		<description><![CDATA[For a moment it was looking like our project got haunted. Suddenly we started getting errors from the libraries being included twice, function exists and class exits kind of error. First few times it was written off as a &#8220;honest&#8221; mistake and fixed on spot, but it continued to happen again and again. Of course, [...]]]></description>
			<content:encoded><![CDATA[<p>For a moment it was looking like our project got haunted. Suddenly we started getting errors from the libraries being included twice, function exists and class exits kind of error. First few times it was written off as a &#8220;honest&#8221; mistake and fixed on spot, but it continued to happen again and again. Of course, it was only showing up on production sites, none of the test sites had this issue.</p>
<p>Some digging in the code and pulling hairs out lead to the issue: include_once was failing us. Yes, it was doing include of the same file again! One little detail &#8211; that only happened when we used both relative and absolute include path, something like:</p>
<p><code>include_once("../includes/fancyLibrary.php");<br />
and<br />
include_once("/absolute/path/to/document/root/includes/fancyLibrary.php");</code></p>
<p>Of course that should not be an issue, according to the PHP documentation.<br />
When I started troubleshooting those includes calling<br />
<code>realpath("../includes/fancyLibrary.php");</code><br />
the truth popped out &#8211; realpath was not returning anything. And then we found why &#8211; there was missing &#8220;read&#8221; attribute on the document root directory, it only had executable bit set (711). Changing permissions to 755 (added read attribute&#8217;s bit) fixed the issue. </p>
<p>So, problems with realpath or include_once PHP functions? Check folders permissions!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.filonov.com/blog/2011/03/04/nightmare-of-php-programmer-include_once-fails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP ftp_connect causing Segmentation Fault (core dumped)</title>
		<link>http://www.filonov.com/blog/2010/12/27/php-ftp_connect-causing-segmentation-fault-core-dumped/</link>
		<comments>http://www.filonov.com/blog/2010/12/27/php-ftp_connect-causing-segmentation-fault-core-dumped/#comments</comments>
		<pubDate>Mon, 27 Dec 2010 21:02:48 +0000</pubDate>
		<dc:creator>Andrei Filonov</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Solaris]]></category>
		<category><![CDATA[troubleshooting]]></category>
		<category><![CDATA[Web development]]></category>

		<guid isPermaLink="false">http://www.filonov.com/blog/?p=57</guid>
		<description><![CDATA[Pretty strange issue and I had hard time to Google it up, so here you go, fellow PHP developers. PHP script which was doing ftp_connect was failing on some installations with Segmentation Fault (core dumped) message. After quite a bit of time wasted looking for answers why, I found that problem was with the FTP [...]]]></description>
			<content:encoded><![CDATA[<p>Pretty strange issue and I had hard time to Google it up, so here you go, fellow PHP developers.</p>
<p>PHP script which was doing ftp_connect was failing on some installations with Segmentation Fault (core dumped) message. After quite a bit of time wasted looking for answers why, I found that problem was with the FTP host name having trailing line break. Well, that host name was coming from config and technically only developers had access to it, so looks like we assumed that variable &#8220;safe&#8221; and were not doing standard checks on special characters. To make things worse that line break is hard to see with debug output, because that line break is too easy to miss when you check variable value in debugger.</p>
<p>I am still not sure why Segmentation Fault (instead of proper message) &#8211; must be some PHP bug (and that server has Solaris OS).</p>
<p>Anyway, hope that helps somebody <img src='http://www.filonov.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.filonov.com/blog/2010/12/27/php-ftp_connect-causing-segmentation-fault-core-dumped/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Eclipse too slow and out of memory</title>
		<link>http://www.filonov.com/blog/2009/08/10/eclipse-too-slow-and-out-of-memory/</link>
		<comments>http://www.filonov.com/blog/2009/08/10/eclipse-too-slow-and-out-of-memory/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 18:16:32 +0000</pubDate>
		<dc:creator>Andrei Filonov</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://www.filonov.com/blog/?p=47</guid>
		<description><![CDATA[Looks like Eclipse PDT was getting quite slow on me, it thinks sometimes 10-15 seconds when I switch between files or save one. My current project is not small one, but still&#8230; Looking around for a solutions I found quite easy tip at http://www.eclipsezone.com/eclipse/forums/t61618.html In short &#8211; I am now running eclipse.exe -vmargs -Xms256m -Xmx256m [...]]]></description>
			<content:encoded><![CDATA[<p>Looks like Eclipse PDT was getting quite slow on me, it thinks sometimes 10-15 seconds when I switch between files or save one. My current project is not small one, but still&#8230; </p>
<p>Looking around for a solutions I found quite easy tip at<br />
<a href="http://www.eclipsezone.com/eclipse/forums/t61618.html">http://www.eclipsezone.com/eclipse/forums/t61618.html</a></p>
<p>In short &#8211; I am now running<br />
<code>eclipse.exe -vmargs -Xms256m -Xmx256m -XX:PermSize=64m -XX:MaxPermSize=64m </code></p>
<p>and my Eclipse is way faster.</p>
<p>Thanks for the tip, Riyad Kalla!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.filonov.com/blog/2009/08/10/eclipse-too-slow-and-out-of-memory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQLSTATE[HY000] [2003] Can&#8217;t connect to MySQL server on &#8216;xxx.xxx.xxx.xxx&#8217; (13)</title>
		<link>http://www.filonov.com/blog/2009/08/07/sqlstatehy000-2003-cant-connect-to-mysql-server-on-xxx-xxx-xxx-xxx-13/</link>
		<comments>http://www.filonov.com/blog/2009/08/07/sqlstatehy000-2003-cant-connect-to-mysql-server-on-xxx-xxx-xxx-xxx-13/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 14:34:44 +0000</pubDate>
		<dc:creator>Andrei Filonov</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[selinux]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[troubleshooting]]></category>

		<guid isPermaLink="false">http://www.filonov.com/blog/?p=45</guid>
		<description><![CDATA[One of the things I wish I had found in Google faster when trying to figure out why PHP script refuses to connect to remote MySQL server issuing an error SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'xxx.xxxx.xxx.xxx' (13) I am able to connect from local shell, so first thought was if something wrong [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things I wish I had found in Google faster when trying to figure out why PHP script refuses to connect to remote MySQL server issuing an error<br />
<code>SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'xxx.xxxx.xxx.xxx' (13)</code></p>
<p>I am able to connect from local shell, so first thought was if something wrong with recent Zend Framework upgrade, but after a while I figured out that answer is very simple &#8211; SELinux was blocking remote connections from PHP scripts executed by Apache web server. The error code (13) at the end of error message means &#8220;permission denied&#8221;, so that&#8217;s the indication to see if you have similar issue or not.</p>
<p>Anyway, login as root and do<br />
<code>setsebool -P httpd_can_network_connect=1</code><br />
to make it work.</p>
<p>Of course, think twice because you make web server a bit less secure, so don&#8217;t do that unless you are sure you need it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.filonov.com/blog/2009/08/07/sqlstatehy000-2003-cant-connect-to-mysql-server-on-xxx-xxx-xxx-xxx-13/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Joomla profiling log</title>
		<link>http://www.filonov.com/blog/2009/05/25/joomla-profiling-log/</link>
		<comments>http://www.filonov.com/blog/2009/05/25/joomla-profiling-log/#comments</comments>
		<pubDate>Mon, 25 May 2009 21:37:39 +0000</pubDate>
		<dc:creator>Andrei Filonov</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[joomla]]></category>
		<category><![CDATA[optimization]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[speed]]></category>

		<guid isPermaLink="false">http://www.filonov.com/blog/?p=37</guid>
		<description><![CDATA[I am using Joomla for the content management, and it looks like my site is getting slow, no, not just slow, it&#8217;s SLOW. Quick check in the MySQL database showed that there is no really big tables which could cause some delays if not indexed properly or getting locked. So, next step would be naturally [...]]]></description>
			<content:encoded><![CDATA[<p>I am using Joomla for the content management, and it looks like my site is getting slow, no, not just slow, it&#8217;s SLOW.</p>
<p>Quick check in the MySQL database showed that there is no really big tables which could cause some delays if not indexed properly or getting locked. So, next step would be naturally looking into the PHP code itself trying to identify bottlenecks.</p>
<p>First of all &#8211; copy everything to test site &#8211; I don&#8217;t really want to shut the site down or display some debug info to the visitors. My test site is actually a linux box which is pretty old one, so it probably will run slower comparing to production, but hopefully still allow me to find which areas of code are causing that.</p>
<p>Next step &#8211; tools. To profile PHP scripts I&#8217;ll use APD (http://pecl.php.net/package/apd). Best case scenario &#8211; you type<br />
<code>pecl install apd </code><br />
in the shell to install package from PECL.<br />
You may also need to add it to PHP configuration, I just created extra config file<br />
<code>/etc/php.d/apd.ini</code><br />
with content<br />
<code>[apd]<br />
zend_extension="/usr/lib/php/modules/apd.so"<br />
apd.dumpdir = /var/apd<br />
apd.statement_tracing = 0</code><br />
(make sure directory specified in dumpdir is created and writable for PHP)</p>
<p>Now we need to add<br />
<code>apd_set_pprof_trace();</code><br />
at the beginning of the index.php script and open the page we want to profile, front page would be a good place to start.</p>
<p>In the dump directory a file created after each page opening, something like<br />
<code>/var/apd/pprof.08711.0</code></p>
<p>Let&#8217;s see what consumes resources now, by running<br />
<code>/usr/bin/pprofp -R /var/apd/pprof.08711.0</code></p>
<p>Oh, that hurts:</p>
<p><code>Total Elapsed Time = 23.58<br />
Total System Time  = 0.65<br />
Total User Time    = 7.18</code></p>
<p>Log in to Joomla admin, go to Extensions->Module Manager, delete all modules I do not really use, but which came pre-setup with Joomla.</p>
<p><code>Total Elapsed Time = 19.51<br />
Total System Time  = 0.24<br />
Total User Time    = 2.48</code></p>
<p>Ok, I am starting to see results already <img src='http://www.filonov.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Now let&#8217;s pay attention to the actual calls and time spent by script in functions.</p>
<p>14 seconds spent in JDocumentRendererModule->getFeed&#8230;<br />
Hm&#8230; I do have a feed from my blog, now I wonder what the cache settings for that block is. So, in admin Module Manager -> mod_feed, advanced settings, cache : use global, time 60 minutes (I think I am ok with blog posts delayed for 1 hour, but it&#8217;s your call, just make sure it won&#8217;t come on every page load). That slashed a lot from the page load &#8211; over 15 sec of wasted time (note &#8211; check why blog feed is so slow, there should be some reasons!!!)</p>
<p>JDocumentHTML->_parseTemplate &#8211; I reviewed template and got rid of calls for modules which are not required or not used (like user1, user2, user3 areas which came with template and similar) &#8211; that saved 1-2 seconds per call.</p>
<p>At this point I have</p>
<p><code>Total Elapsed Time = 2.82<br />
Total System Time  = 0.21<br />
Total User Time    = 2.48</code></p>
<p>Which is way better, but still makes me wonder if it can run faster. </p>
<p>There are other options to play with<br />
<code>/usr/bin/pprofp -u /var/apd/pprof.09573.15</code><br />
gives an idea what subroutines consumed most user time.</p>
<p>Last but not least: for the profiling purposes I turned off cache (Site->admin->global configuration). For life site it should be turned on with reasonable time to keep cached copy, that shaves off another 50% of execution time on subsequent calls of the same page.</p>
<p><code>Total Elapsed Time = 1.78<br />
Total System Time  = 0.17<br />
Total User Time    = 1.55</code></p>
<p>For now it&#8217;s as good as it gets on my old server, next thing to do would be profiling the script on the production server to see what it looks like there.</p>
<p>Another tip: if you profile a live site, restrict profiler calls to your own IP:<br />
<code>if($_SERVER['REMOTE_ADDR'] == "xxx.xxx.xxx.xxx") {<br />
apd_set_pprof_trace();<br />
}</code><br />
otherwise you may get buried in a number of trace logs.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.filonov.com/blog/2009/05/25/joomla-profiling-log/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Freelance PHP positions</title>
		<link>http://www.filonov.com/blog/2009/05/06/freelance-php-positions/</link>
		<comments>http://www.filonov.com/blog/2009/05/06/freelance-php-positions/#comments</comments>
		<pubDate>Wed, 06 May 2009 16:28:41 +0000</pubDate>
		<dc:creator>Andrei Filonov</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[freelance]]></category>
		<category><![CDATA[jobs]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://filonov.com/blog/2009/05/06/freelance-php-positions/</guid>
		<description><![CDATA[Do you know PHP and thinking about getting some freelance job? You are not alone for sure, freelancing is a good way to get an extra income, to get started building your portfolio or to stop coming to the office and work from home. Here is a good list of freelance positions for PHP developers: [...]]]></description>
			<content:encoded><![CDATA[<p>Do you know PHP and thinking about getting some freelance job? You are not alone for sure, freelancing is a good way to get an extra income, to get started building your portfolio or to stop coming to the office and work from home.</p>
<p>Here is a good list of freelance positions for PHP developers:<br />
<a href="http://workfromhomephpjobs.blogspot.com/">http://workfromhomephpjobs.blogspot.com/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.filonov.com/blog/2009/05/06/freelance-php-positions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

