<?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>Florent Clairambault &#187; PHP</title>
	<atom:link href="http://florent.clairambault.fr/tag/php/feed" rel="self" type="application/rss+xml" />
	<link>http://florent.clairambault.fr</link>
	<description></description>
	<lastBuildDate>Sat, 04 Feb 2012 19:56:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.4-alpha-19719</generator>
		<item>
		<title>Prestashop and APC</title>
		<link>http://florent.clairambault.fr/prestashop-and-apc?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=prestashop-and-apc</link>
		<comments>http://florent.clairambault.fr/prestashop-and-apc#comments</comments>
		<pubDate>Mon, 04 Oct 2010 22:18:45 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[APC]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[prestashop]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=3019</guid>
		<description><![CDATA[When you do a fresh install of prestashop, just after it finishes you need to rename the &#8220;admin&#8221; directory. The problem is that with the last two installs we did (as part of WebIngenia), we ended up with a blank/empty/white webpage. The only way to solve it was to clear the opcode cache from APC. [...]]]></description>
			<content:encoded><![CDATA[<div style="float: right; position: relative"><img src="http://i.mivi.fr/b32fb17dc7b8e1bd0f79ab84376cd851d332d889.x.128.jpg" alt="prestashop" /></div>
<p>When you do a fresh install of prestashop, just after it finishes you need to rename the &#8220;admin&#8221; directory. The problem is that with the last two installs we did (as part of <a href="http://webingenia.com">WebIngenia</a>), we ended up with a blank/empty/white webpage. The only way to solve it was to clear the opcode cache from APC.<br />
So, if you encounter the same problem, you know what to do, you just need to clear the APC opcode cache and continue the install.</p>
<p>BTW, sorry for not having properly maintained this blog recently. Not enough free time. I&#8217;ll release an updated version of the TC65 guide pretty soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/prestashop-and-apc/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>WP-Codebox fix so that it doesn&#8217;t prevent posts export</title>
		<link>http://florent.clairambault.fr/wp-codebox-fix-so-that-it-doesnt-prevent-posts-export?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wp-codebox-fix-so-that-it-doesnt-prevent-posts-export</link>
		<comments>http://florent.clairambault.fr/wp-codebox-fix-so-that-it-doesnt-prevent-posts-export#comments</comments>
		<pubDate>Sat, 15 May 2010 07:00:08 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[WP Codebox]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=2695</guid>
		<description><![CDATA[If you have a PHP configured with some open_basedir restriction (which is recommended), the WP-Codebox plugin will prevent you from exporting the posts of your blog. Go to your blog, go in the &#8220;wp-content/plugins/wp-codebox&#8221; dir and edit the &#8220;wp-codebox.php&#8221; file : On line 27, you should have : 1 2 include_once &#34;../../../wp-config.php&#34;; include_once &#34;../../../wp-settings.php&#34;; Well, [...]]]></description>
			<content:encoded><![CDATA[<p>If you have a PHP configured with some <a href="http://www.php.net/manual/en/ini.core.php#ini.open-basedir">open_basedir restriction</a> (which is recommended), the WP-Codebox plugin will prevent you from exporting the posts of your blog.</p>
<p>Go to your blog, go in the &#8220;wp-content/plugins/wp-codebox&#8221; dir and edit the &#8220;wp-codebox.php&#8221; file :<br />
On line 27, you should have :</p>

<div class="wp_codebox"><table><tr id="p26953"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2695code3"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">include_once</span> <span style="color: #0000ff;">&quot;../../../wp-config.php&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">include_once</span> <span style="color: #0000ff;">&quot;../../../wp-settings.php&quot;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Well, it fails because the plugin doesn&#8217;t use the good practices, so it&#8217;s pretty easy to fix :</p>

<div class="wp_codebox"><table><tr id="p26954"><td class="line_numbers"><pre>1
2
</pre></td><td class="code" id="p2695code4"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span> ABSPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'/wp-config.php'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span> ABSPATH<span style="color: #339933;">.</span><span style="color: #0000ff;">'/wp-settings.php'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>I&#8217;d like to thank the developer of this plugin for doing such a great job. It brings the power of <a href="http://qbnz.com/highlighter/">geshi</a> (not the latest version by the way) into <a href="http://wordpress.org/">wordpress</a>.</p>
<div style="display: none">
BTW, why change :<br />
* include_once to require_once : Why should we accept that a file couldn&#8217;t be included on go on ?<br />
* double quote to simple quote : php reads it faster because it doesn&#8217;t parse vars (&#8220;$&#8221; starting words).<br />
* no parenthesis to parenthesis : Well, it&#8217;s a method isn&#8217;t it ?
</div>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/wp-codebox-fix-so-that-it-doesnt-prevent-posts-export/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Linux prioritization : do more with less</title>
		<link>http://florent.clairambault.fr/linux-prioritization-do-more-with-less?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=linux-prioritization-do-more-with-less</link>
		<comments>http://florent.clairambault.fr/linux-prioritization-do-more-with-less#comments</comments>
		<pubDate>Sun, 07 Mar 2010 18:34:04 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[cfq]]></category>
		<category><![CDATA[ionice]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[nice]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[prioritization]]></category>
		<category><![CDATA[real-time]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=2452</guid>
		<description><![CDATA[I find the concept of prioritization very interesting. It just enables you to do more with less. Doesn&#8217;t that sound great ? Let&#8217;s say you want to be able to respond to user requests as fast as possible but update your data in a low priority manner : You can set the process CPU priority [...]]]></description>
			<content:encoded><![CDATA[<p>I find the concept of prioritization very interesting. It just enables you to do more with less. Doesn&#8217;t that sound great ?</p>
<p>Let&#8217;s say you want to be able to respond to user requests as fast as possible but update your data in a low priority manner :<br />
You can set the process CPU priority from -20 (high priority) to 19 (low priority) by using the command :</p>

<div class="wp_codebox"><table><tr id="p245210"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2452code10"><pre class="sh" style="font-family:monospace;">nice -n &lt;priority&gt; &lt;command&gt;</pre></td></tr></table></div>

<p>You can set the process IO priority in 4 classes (0: none, 1: realtime, 2: best-effort, 3: idle) with some priorities within these classes (0-7, lower being higher prio). But you have to enable the CFQ (Complete Fair Queueing) scheduler first by typing something like that :</p>

<div class="wp_codebox"><table><tr id="p245211"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2452code11"><pre class="sh" style="font-family:monospace;">echo cfq &gt;/sys/block/hda/queue/scheduler</pre></td></tr></table></div>

<p>So the ultimate low priority command will be</p>

<div class="wp_codebox"><table><tr id="p245212"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2452code12"><pre class="sh" style="font-family:monospace;">ionice -c 3 nice -n 20 &lt;command&gt;</pre></td></tr></table></div>

<p>But sometimes changing the CPU and IO priority won&#8217;t change much because the problem you might have might occur within the SQL server for say. So what you do ? Well, you could slow down your low priority program. If you have a low priority php script, you could do it like that :</p>

<div class="wp_codebox"><table><tr id="p245213"><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code" id="p2452code13"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <a href="http://www.php.net/list"><span style="color: #990000;">list</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$load</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/explode"><span style="color: #990000;">explode</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/proc/loadavg'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'sleeping '</span><span style="color: #339933;">.</span><span style="color: #000088;">$load</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;s<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
    <a href="http://www.php.net/usleep"><span style="color: #990000;">usleep</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$load</span> <span style="color: #339933;">*</span> <span style="color: #cc66cc;">1000000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>This program will make a loop that will slow down with the increasing load. It means that this program will always keep space of the system, even if it&#8217;s run hundreads of time.</p>
<p>So yeah, you can now manage efficiently CPU and disk. Are you done ? Not really, there&#8217;s still the memory issue. Memory (RAM) is always fast unless there&#8217;s no memory left, then it&#8217;s paged and everything becomes thousand times slower. You can only disable the virtual memory (swap on Linux), set some memory allocation limits (with ulimit), but that&#8217;s pretty much it.<br />
I would personnally recommend to disable swap and always take more RAM than needed. On servers swap prevent them from having to kill process, but they are so much slowed by it that the whole system is slowed down. And then even ssh server is so slow you have an ssh timeout before reaching the shell.</p>
<p>So, Linux has a great scheduling capacity. But what about NOT scheduling AT ALL ? Well, Linux is also very able to do that. You can put some process in real-time mode, these processes won&#8217;t be interupted by anything unless they are sleeping or waiting for an I/O event.<br />
You can use the Real-Time (RT) mode using the rtprio command :</p>

<div class="wp_codebox"><table><tr id="p245214"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2452code14"><pre class="sh" style="font-family:monospace;">rtprio 99 &lt;command&gt;</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/linux-prioritization-do-more-with-less/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dirty WordPress APC caching</title>
		<link>http://florent.clairambault.fr/dirty-wordpress-apc-caching?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=dirty-wordpress-apc-caching</link>
		<comments>http://florent.clairambault.fr/dirty-wordpress-apc-caching#comments</comments>
		<pubDate>Sat, 13 Feb 2010 08:00:36 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[APC]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=2347</guid>
		<description><![CDATA[One or two weeks ago, I made a simple AB benchmarking test on a PHP site I built, it was ok. Then I did the same test on this blog and well&#8230; It was freaking slow&#8230; On 100 pages with 10 concurrent access, it took 3.5 to 10s to render. Well, I thought I should [...]]]></description>
			<content:encoded><![CDATA[<p>One or two weeks ago, I made a simple <a href="http://httpd.apache.org/docs/2.0/programs/ab.html">AB</a> benchmarking test on a PHP site I built, it was ok. Then I did the same test on this blog and well&#8230; It was freaking slow&#8230; On 100 pages with 10 concurrent access, it took 3.5 to 10s to render. Well, I thought I should remove all these plugins I installed to make me and my blog famous (they didn&#8217;t perform well). It reduced the generation time by something like 100 ms.</p>
<p>So I had the brilliant idea to put everything in an APC cache, <a href="http://www.idontplaydarts.com/2009/08/caching-wordpress-as-static-html-using-apc/">someone</a> had the same idea.</p>
<p>So I approximatively did the same thing :</p>
<p>In the beginning of the index.php file :</p>

<div class="wp_codebox"><table><tr id="p234720"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code" id="p2347code20"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_METHOD'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'GET'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// This key will identify the page used</span>
        <span style="color: #000088;">$cacheKey</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'WP_'</span><span style="color: #339933;">.</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'HTTP_HOST'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><a href="http://www.php.net/md5"><span style="color: #990000;">md5</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// We try to get this page</span>
        <span style="color: #000088;">$cacheData</span> <span style="color: #339933;">=</span> apc_fetch<span style="color: #009900;">&#40;</span><span style="color: #000088;">$cacheKey</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// If we got something</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_array"><span style="color: #990000;">is_array</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$cacheData</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">// We give each header</span>
                <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$cacheData</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$h</span> <span style="color: #009900;">&#41;</span>
                        <a href="http://www.php.net/header"><span style="color: #990000;">header</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$h</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
                <span style="color: #666666; font-style: italic;">// And the content</span>
                <a href="http://www.php.net/die"><span style="color: #990000;">die</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$cacheData</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #666666; font-style: italic;">// If we're still here, we have no cache, so we'll start caching right now</span>
        <a href="http://www.php.net/ob_start"><span style="color: #990000;">ob_start</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>In the end of the index.php file :</p>

<div class="wp_codebox"><table><tr id="p234721"><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code" id="p2347code21"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// We have a cache key, it means we have something to cache</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$cacheKey</span> <span style="color: #009900;">&#41;</span>
        apc_store<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$cacheKey</span><span style="color: #339933;">,</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span> <a href="http://www.php.net/headers_list"><span style="color: #990000;">headers_list</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <a href="http://www.php.net/ob_get_contents"><span style="color: #990000;">ob_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">900</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>And once it&#8217;s cached it performs well, to make it short it can serve in mean time of 1 ms and gives a general bandwidth of 200 MB/s. As you can guess, these tests are made locally and this is normal.</p>

<div class="wp_codebox"><table><tr id="p234722"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code" id="p2347code22"><pre class="txt" style="font-family:monospace;">[root@s15342968 ~]# ab -n 100  &quot;http://florent.clairambault.fr/&quot;
This is ApacheBench, Version 2.0.40-dev &lt;$Revision: 1.146 $&gt; apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/
&nbsp;
Benchmarking florent.clairambault.fr (be patient).....done
&nbsp;
&nbsp;
Server Software:        Apache/2.2.8
Server Hostname:        florent.clairambault.fr
Server Port:            80
&nbsp;
Document Path:          /
Document Length:        161165 bytes
&nbsp;
Concurrency Level:      1
Time taken for tests:   0.119899 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      16156100 bytes
HTML transferred:       16116500 bytes
Requests per second:    834.04 [#/sec] (mean)
Time per request:       1.199 [ms] (mean)
Time per request:       1.199 [ms] (mean, across all concurrent requests)
Transfer rate:          131585.75 [Kbytes/sec] received
&nbsp;
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     1    1   0.0      1       1
Waiting:        0    0   0.1      0       1
Total:          1    1   0.0      1       1
&nbsp;
Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      1
  99%      1
 100%      1 (longest request)</pre></td></tr></table></div>


<div class="wp_codebox"><table><tr id="p234723"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code" id="p2347code23"><pre class="txt" style="font-family:monospace;">[root@s15342968 ~]# ab -n 100 -c 10  &quot;http://florent.clairambault.fr/&quot;
This is ApacheBench, Version 2.0.40-dev &lt;$Revision: 1.146 $&gt; apache-2.0
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Copyright 2006 The Apache Software Foundation, http://www.apache.org/
&nbsp;
Benchmarking florent.clairambault.fr (be patient).....done
&nbsp;
&nbsp;
Server Software:        Apache/2.2.8
Server Hostname:        florent.clairambault.fr
Server Port:            80
&nbsp;
Document Path:          /
Document Length:        161165 bytes
&nbsp;
Concurrency Level:      10
Time taken for tests:   0.47897 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      16156100 bytes
HTML transferred:       16116500 bytes
Requests per second:    2087.81 [#/sec] (mean)
Time per request:       4.790 [ms] (mean)
Time per request:       0.479 [ms] (mean, across all concurrent requests)
Transfer rate:          329394.31 [Kbytes/sec] received
&nbsp;
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     1    4   1.3      4      10
Waiting:        0    1   1.0      1       4
Total:          1    4   1.3      4      10
&nbsp;
Percentage of the requests served within a certain time (ms)
  50%      4
  66%      4
  75%      5
  80%      5
  90%      6
  95%      6
  98%      8
  99%     10
 100%     10 (longest request)</pre></td></tr></table></div>


<div class="wp_codebox"><table><tr id="p234724"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
</pre></td><td class="code" id="p2347code24"><pre class="php" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>root<span style="color: #339933;">@</span>s15342968 ~<span style="color: #009900;">&#93;</span><span style="color: #666666; font-style: italic;"># ab -n 10000 -c 10  &quot;http://florent.clairambault.fr/&quot;
</span>This is ApacheBench<span style="color: #339933;">,</span> Version 2<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>40<span style="color: #339933;">-</span>dev <span style="color: #339933;">&lt;</span><span style="color: #000088;">$Revision</span><span style="color: #339933;">:</span> <span style="color:#800080;">1.146</span> $<span style="color: #339933;">&gt;</span> apache<span style="color: #339933;">-</span><span style="color:#800080;">2.0</span>
Copyright <span style="color: #cc66cc;">1996</span> Adam Twiss<span style="color: #339933;">,</span> Zeus Technology Ltd<span style="color: #339933;">,</span> http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//www.zeustech.net/</span>
Copyright <span style="color: #cc66cc;">2006</span> The Apache Software Foundation<span style="color: #339933;">,</span> http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//www.apache.org/</span>
&nbsp;
Benchmarking florent<span style="color: #339933;">.</span>clairambault<span style="color: #339933;">.</span>fr <span style="color: #009900;">&#40;</span>be patient<span style="color: #009900;">&#41;</span>
Completed <span style="color: #cc66cc;">1000</span> requests
Completed <span style="color: #cc66cc;">2000</span> requests
Completed <span style="color: #cc66cc;">3000</span> requests
Completed <span style="color: #cc66cc;">4000</span> requests
Completed <span style="color: #cc66cc;">5000</span> requests
Completed <span style="color: #cc66cc;">6000</span> requests
Completed <span style="color: #cc66cc;">7000</span> requests
Completed <span style="color: #cc66cc;">8000</span> requests
Completed <span style="color: #cc66cc;">9000</span> requests
Finished <span style="color: #cc66cc;">10000</span> requests
&nbsp;
&nbsp;
Server Software<span style="color: #339933;">:</span>        Apache<span style="color: #339933;">/</span>2<span style="color: #339933;">.</span>2<span style="color: #339933;">.</span>8
Server Hostname<span style="color: #339933;">:</span>        florent<span style="color: #339933;">.</span>clairambault<span style="color: #339933;">.</span>fr
Server Port<span style="color: #339933;">:</span>            <span style="color: #cc66cc;">80</span>
&nbsp;
Document Path<span style="color: #339933;">:</span>          <span style="color: #339933;">/</span>
Document Length<span style="color: #339933;">:</span>        <span style="color: #cc66cc;">161165</span> bytes
&nbsp;
Concurrency Level<span style="color: #339933;">:</span>      <span style="color: #cc66cc;">10</span>
<a href="http://www.php.net/time"><span style="color: #990000;">Time</span></a> taken <span style="color: #b1b100;">for</span> tests<span style="color: #339933;">:</span>   <span style="color:#800080;">7.898135</span> seconds
Complete requests<span style="color: #339933;">:</span>      <span style="color: #cc66cc;">10000</span>
Failed requests<span style="color: #339933;">:</span>        <span style="color: #cc66cc;">0</span>
Write errors<span style="color: #339933;">:</span>           <span style="color: #cc66cc;">0</span>
Total transferred<span style="color: #339933;">:</span>      <span style="color: #cc66cc;">1616094683</span> bytes
HTML transferred<span style="color: #339933;">:</span>       <span style="color: #cc66cc;">1612133495</span> bytes
Requests per second<span style="color: #339933;">:</span>    <span style="color:#800080;">1266.12</span> <span style="color: #009900;">&#91;</span><span style="color: #666666; font-style: italic;">#/sec] (mean)
</span><a href="http://www.php.net/time"><span style="color: #990000;">Time</span></a> per request<span style="color: #339933;">:</span>       <span style="color:#800080;">7.898</span> <span style="color: #009900;">&#91;</span>ms<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#40;</span>mean<span style="color: #009900;">&#41;</span>
<a href="http://www.php.net/time"><span style="color: #990000;">Time</span></a> per request<span style="color: #339933;">:</span>       <span style="color:#800080;">0.790</span> <span style="color: #009900;">&#91;</span>ms<span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#40;</span>mean<span style="color: #339933;">,</span> across all concurrent requests<span style="color: #009900;">&#41;</span>
Transfer rate<span style="color: #339933;">:</span>          <span style="color:#800080;">199821.47</span> <span style="color: #009900;">&#91;</span>Kbytes<span style="color: #339933;">/</span>sec<span style="color: #009900;">&#93;</span> received
&nbsp;
Connection Times <span style="color: #009900;">&#40;</span>ms<span style="color: #009900;">&#41;</span>
              <a href="http://www.php.net/min"><span style="color: #990000;">min</span></a>  mean<span style="color: #009900;">&#91;</span><span style="color: #339933;">+/-</span>sd<span style="color: #009900;">&#93;</span> median   <a href="http://www.php.net/max"><span style="color: #990000;">max</span></a>
Connect<span style="color: #339933;">:</span>        <span style="color: #cc66cc;">0</span>    <span style="color: #cc66cc;">0</span>   <span style="color:#800080;">0.9</span>      <span style="color: #cc66cc;">0</span>       <span style="color: #cc66cc;">7</span>
Processing<span style="color: #339933;">:</span>     <span style="color: #cc66cc;">2</span>    <span style="color: #cc66cc;">6</span>   <span style="color:#800080;">1.6</span>      <span style="color: #cc66cc;">7</span>      <span style="color: #cc66cc;">13</span>
Waiting<span style="color: #339933;">:</span>        <span style="color: #cc66cc;">0</span>    <span style="color: #cc66cc;">1</span>   <span style="color:#800080;">1.4</span>      <span style="color: #cc66cc;">1</span>       <span style="color: #cc66cc;">8</span>
Total<span style="color: #339933;">:</span>          <span style="color: #cc66cc;">2</span>    <span style="color: #cc66cc;">7</span>   <span style="color:#800080;">1.5</span>      <span style="color: #cc66cc;">7</span>      <span style="color: #cc66cc;">16</span>
&nbsp;
Percentage of the requests served within a certain <a href="http://www.php.net/time"><span style="color: #990000;">time</span></a> <span style="color: #009900;">&#40;</span>ms<span style="color: #009900;">&#41;</span>
  <span style="color: #cc66cc;">50</span><span style="color: #339933;">%</span>      <span style="color: #cc66cc;">7</span>
  <span style="color: #cc66cc;">66</span><span style="color: #339933;">%</span>      <span style="color: #cc66cc;">8</span>
  <span style="color: #cc66cc;">75</span><span style="color: #339933;">%</span>      <span style="color: #cc66cc;">8</span>
  <span style="color: #cc66cc;">80</span><span style="color: #339933;">%</span>      <span style="color: #cc66cc;">8</span>
  <span style="color: #cc66cc;">90</span><span style="color: #339933;">%</span>      <span style="color: #cc66cc;">9</span>
  <span style="color: #cc66cc;">95</span><span style="color: #339933;">%</span>     <span style="color: #cc66cc;">10</span>
  <span style="color: #cc66cc;">98</span><span style="color: #339933;">%</span>     <span style="color: #cc66cc;">11</span>
  <span style="color: #cc66cc;">99</span><span style="color: #339933;">%</span>     <span style="color: #cc66cc;">11</span>
 <span style="color: #cc66cc;">100</span><span style="color: #339933;">%</span>     <span style="color: #cc66cc;">16</span> <span style="color: #009900;">&#40;</span>longest request<span style="color: #009900;">&#41;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/dirty-wordpress-apc-caching/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>WordPress with APC</title>
		<link>http://florent.clairambault.fr/wordpress-with-apc?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=wordpress-with-apc</link>
		<comments>http://florent.clairambault.fr/wordpress-with-apc#comments</comments>
		<pubDate>Fri, 12 Feb 2010 20:00:17 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[APC]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=2339</guid>
		<description><![CDATA[I updated APC from 3.0 to 3.1 because it totally locked my webserver, it was making it accept HTTP connection but never give any reply. I had some problem accessing the WordPress 3.0 (latest SVN version) admin interface after that upgrade : 1 Fatal error: Call to undefined function wp_dashboard_setup() in /home/sites/clairambault.fr/florent/wp-admin/index.php on line 15 [...]]]></description>
			<content:encoded><![CDATA[<p>I updated <a href="http://php.net/manual/en/book.apc.php">APC</a> from 3.0 to 3.1 because it totally locked my webserver, it was making it accept HTTP connection but never give any reply. </p>
<p>I had some problem accessing the WordPress 3.0 (latest SVN version) admin interface after that upgrade :</p>

<div class="wp_codebox"><table><tr id="p233928"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2339code28"><pre class="error" style="font-family:monospace;">Fatal error: Call to undefined function wp_dashboard_setup() in /home/sites/clairambault.fr/florent/wp-admin/index.php on line 15</pre></td></tr></table></div>

<p>the bad line is :</p>

<div class="wp_codebox"><table><tr id="p233929"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2339code29"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span>ABSPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'wp-admin/includes/dashboard.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>I just found out <a href="http://wordpress.org/support/topic/284464">here</a> it was because I activated <a href="http://php.net/manual/en/book.apc.php">APC</a> with the &#8220;apc.include_once_override&#8221; option set to 1. If you encounter the same problem, just set it to 0 or change the include by something without the ABSPATH constant like for instance :</p>

<div class="wp_codebox"><table><tr id="p233930"><td class="line_numbers"><pre>1
</pre></td><td class="code" id="p2339code30"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./includes/dashboard.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p>Note : requiring local files with &#8220;./&#8221; makes you save some CPU time.</p>
<p>I personally chose to change the wp-admin/index.php file because I didn&#8217;t want to reduce the performance of the other applications (I haven&#8217;t done any benchmark of the performance difference though).</p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/wordpress-with-apc/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Push (Comet) or pull ?</title>
		<link>http://florent.clairambault.fr/push-comet-or-pull?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=push-comet-or-pull</link>
		<comments>http://florent.clairambault.fr/push-comet-or-pull#comments</comments>
		<pubDate>Mon, 23 Nov 2009 12:45:30 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[APE]]></category>
		<category><![CDATA[Comet]]></category>
		<category><![CDATA[CometD]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[pull]]></category>
		<category><![CDATA[push]]></category>
		<category><![CDATA[Silverlight]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=1972</guid>
		<description><![CDATA[What is it ? Most of the modern web applications display recently updated data, and to do that they need to get he latest data very frequently. Some of them even include some real-time chat (Gmail Chat, Facebook chat). How ? That&#8217;s the interesting part. Pull is pretty dumb. You do a request very frequently [...]]]></description>
			<content:encoded><![CDATA[<p><strong>What is it ?</strong><br />
Most of the modern web applications display recently updated data, and to do that they need to get he latest data very frequently. Some of them even include some real-time chat (Gmail Chat, Facebook chat).</p>
<p><strong>How ?</strong><br />
That&#8217;s the interesting part.</p>
<ul>
<li>Pull is pretty dumb. You do a request very frequently and you see if anything new appeared. This consumes some bandwidth, some resources (because server has to check if data has actually changed).</li>
<li>Push is going back to the source : Once you&#8217;ve made the request on the server, it doesn&#8217;t reply instantly. It will wait for something before sending anything. So push over HTTP is in fact a pull with a sleeping response. Using push over HTTP is called Comet.</li>
</ul>
<p>So pushing data isn&#8217;t very complex, it just requires a special server to transmit some data (text, html, xml, or image) over an already opened HTTP connection. </p>
<p>Why do we need some special servers ? Because our current servers aren&#8217;t build to make people wait. Some geeks made some example of PHP code being able to make some Comet response but they all use looping usleep. If you used it, you would end up totally killing your server with the growing number of clients.<br />
This is the very interesting part of Comet : It doesn&#8217;t consumes more resources, it just requires additional server software.</p>
<p><strong>Two types of push</strong><br />
They are two types of push :</p>
<ul>
<li><a name="long_poll">The multiple limited time push requests or long poll mode</a> : You make a request and each time you get the response the connection is closed and you have to make an other pull. It&#8217;s easier to implement but you could end up doing a lot of http requests, which means generating quite some data.</li>
<li>The streaming push mode : You open the connection once, and then data comes asynchronously, and the connection is never closed. If it &#8220;accidentally&#8221; closes, the client reopens it.</li>
</ul>
<p><strong>How do do some push enabled web applications</strong><br />
You rethink your software so that it uses the push server.</p>
<p>On PHP, you can use <a href="http://www.ape-project.org/">The Ajax Push Engine</a>.<br />
On pure .Net environnement, you can use <a href="http://msdn.microsoft.com/fr-fr/library/system.servicemodel.wsdualhttpbinding.aspx">WCF WsDualHttpBinding</a> to serve data.<br />
The <a href="http://cometdproject.dojotoolkit.org/">CometD</a> is a stable opensource comet server project. <a href="http://jquery.com/">JQuery</a> and <a href="http://dojotoolkit.org/">Dojo</a> can consume it.<br />
You have <a href="http://www.lightstreamer.com/products.htm">LightStreamer</a>, a commercial product with a free license. It can be connected with nearly anything (the only unsupported type of server seems to be PHP) or <a href="http://www.stream-hub.com/features.html">StreamHub</a> which has a very restrictive free license.</p>
<p><strong>Why some people still use Flex ou SilverLight ?</strong><br />
Http push / Comet requires a complex parallel server infrastructure and it only solves the push (server to client realtime data transmission) problem. When data is received, you still have to treat and display it. Managing this is a lot harder with javascript than it is in Flex ou SilverLight.</p>
<p>By the way, on flex, silverlight, flash, java applets you can use your own sockets to transmit data. This is a very good solution, there a good chance it will consume less bandwidth. But you have to remember that not using the HTTP protocol can create some problems as some companies block every other protocols on their internet gateways.</p>
<p><strong>W3C is on it !</strong><br />
W3C is thinking about adding a <a href="http://dev.w3.org/html5/websockets/">WebSocket specification</a>. This could be a very good thing as it would standardize this non-standardized part of the web.</p>
<p><strong>Push outside the web</strong><br />
Push isn&#8217;t a web specific concept. Any instant messaging service (like MSN, Jabber, Yahoo or ICQ) does support push.</p>
<p>Any system supporting sockets enables you to make push enabled applications. If you consider the mobile OSes, they all support socket, so they all support push. Androïd supports push by socket, J2ME supports push by sockets, iPhone supports push by Apple push system or sockets and it seems BlackBerry supports it by the BlackBerry push service or sockets.</p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/push-comet-or-pull/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic error reporting in PHP</title>
		<link>http://florent.clairambault.fr/automatic-php-error-reporting?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=automatic-php-error-reporting</link>
		<comments>http://florent.clairambault.fr/automatic-php-error-reporting#comments</comments>
		<pubDate>Sun, 15 Feb 2009 08:35:37 +0000</pubDate>
		<dc:creator>Florent Clairambault</dc:creator>
				<category><![CDATA[English]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://florent.clairambault.fr/?p=167</guid>
		<description><![CDATA[I edited this page on the 21 March 2010 because a lot of people seem interested and the code as since improved ! PHP has a pretty interesting feature, you can define a callback method to &#8220;catch&#8221; any error &#8220;thrown&#8221; in your code. And I&#8217;m sure most of you don&#8217;t use it. It&#8217;s really usefull [...]]]></description>
			<content:encoded><![CDATA[<p><em>I edited this page on the 21 March 2010 because a lot of people seem interested and the code as since improved !</em></p>
<p>PHP has a pretty interesting feature, you can define a callback method to &#8220;catch&#8221; any error &#8220;thrown&#8221; in your code. And I&#8217;m sure most of you don&#8217;t use it. It&#8217;s really usefull when you want to make sure to detect error before any user reports it (which can takes time). This is all about avoiding to demolish with some lame errors your &#8220;user experience&#8221;.</p>
<p>I now use it in each of my index.php pages (which generally loads every other pages), but to speed things up I make it load the actual method only when the error is &#8220;catched&#8221;.</p>
<p>This is the code :</p>

<div class="wp_codebox"><table><tr id="p16734"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
</pre></td><td class="code" id="p167code34"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> lightErrorHandler<span style="color: #009900;">&#40;</span><span style="color: #000088;">$errno</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errstr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errfile</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errline</span><span style="color: #339933;">,</span> <span style="color: #000088;">$shutdown</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// When called from the shutdown function, the relative path doesn't work anymore.</span>
	<span style="color: #666666; font-style: italic;">// You have to load the errorHandler function from its absolute path</span>
	<span style="color: #666666; font-style: italic;">// If you don't like that method, you can always preload this function.</span>
	<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/home/website/mysite.com/dev-www/include/error/errorHandler.inc.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> errorHandler<span style="color: #009900;">&#40;</span><span style="color: #000088;">$errno</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errstr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errfile</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errline</span><span style="color: #339933;">,</span> <span style="color: #000088;">$shutdown</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<a href="http://www.php.net/set_error_handler"><span style="color: #990000;">set_error_handler</span></a><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'lightErrorHandler'</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">E_ALL</span> ^ <span style="color: #009900; font-weight: bold;">E_NOTICE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> lightExceptionHandler<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$exception</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'./include/error/exceptionHandler.inc.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #b1b100;">return</span> exceptionHandler<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$exception</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
set_exception_handler<span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'lightExceptionHandler'</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> shutdown_function<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><a href="http://www.php.net/is_null"><span style="color: #990000;">is_null</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$e</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/error_get_last"><span style="color: #990000;">error_get_last</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">false</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #000088;">$e</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;</span> <span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">E_ALL</span> ^ <span style="color: #009900; font-weight: bold;">E_NOTICE</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		lightErrorHandler<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$e</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'type'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$e</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'message'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$e</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'file'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$e</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'line'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<a href="http://www.php.net/register_shutdown_function"><span style="color: #990000;">register_shutdown_function</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'shutdown_function'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>include/error/errorHandler.inc.php :</strong></p>

<div class="wp_codebox"><table><tr id="p16735"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code" id="p167code35"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> errorHandler<span style="color: #009900;">&#40;</span><span style="color: #000088;">$errno</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errstr</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errfile</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errline</span><span style="color: #339933;">,</span> <span style="color: #000088;">$shutdown</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$engine</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$tab</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
	        <span style="color: #0000ff;">'no'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$errno</span><span style="color: #339933;">,</span>
	        <span style="color: #0000ff;">'str'</span>   <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$errstr</span><span style="color: #339933;">,</span>
	        <span style="color: #0000ff;">'file'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$errfile</span><span style="color: #339933;">,</span>
	        <span style="color: #0000ff;">'line'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$errline</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'An error happened :'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'Error : '</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">.</span><a href="http://www.php.net/print_r"><span style="color: #990000;">print_r</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$tab</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'StackTrace : '</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">.</span><a href="http://www.php.net/print_r"><span style="color: #990000;">print_r</span></a><span style="color: #009900;">&#40;</span> <a href="http://www.php.net/debug_backtrace"><span style="color: #990000;">debug_backtrace</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'Memory state : '</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">.</span><a href="http://www.php.net/print_r"><span style="color: #990000;">print_r</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$GLOBALS</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<a href="http://www.php.net/mail"><span style="color: #990000;">mail</span></a><span style="color: #009900;">&#40;</span>
	        <span style="color: #0000ff;">'email@company.com'</span><span style="color: #339933;">,</span>
	        <span style="color: #0000ff;">'MyProject : Error : '</span><span style="color: #339933;">.</span><span style="color: #000088;">$errfile</span><span style="color: #339933;">.</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">.</span><span style="color: #000088;">$errline</span><span style="color: #339933;">,</span>
	        <span style="color: #000088;">$message</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$target</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$errfile</span><span style="color: #339933;">.</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">.</span><span style="color: #000088;">$errline</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #000088;">$engine</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'bug'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #339933;">!</span> <span style="color: #000088;">$shutdown</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$engine</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'bug'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		Logger<span style="color: #339933;">::</span><a href="http://www.php.net/log"><span style="color: #990000;">log</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'message'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Error : '</span><span style="color: #339933;">.</span><span style="color: #000088;">$errstr</span><span style="color: #339933;">.</span><span style="color: #0000ff;">' ('</span><span style="color: #339933;">.</span><span style="color: #000088;">$errno</span><span style="color: #339933;">.</span><span style="color: #0000ff;">')'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'type'</span>			<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'error/codeError'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'target'</span>		<span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$target</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><a href="http://www.php.net/min"><span style="color: #990000;">min</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">250</span><span style="color: #339933;">,</span> <a href="http://www.php.net/strlen"><span style="color: #990000;">strlen</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$target</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'data'</span>			<span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/serialize"><span style="color: #990000;">serialize</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'level'</span>			<span style="color: #339933;">=&gt;</span> Logger<span style="color: #339933;">::</span><span style="color: #004000;">CRITICAL</span>
		<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>include/error/exceptionHandler.inc.php :</strong></p>

<div class="wp_codebox"><table><tr id="p16736"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
</pre></td><td class="code" id="p167code36"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> exceptionHandler<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$exception</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$engine</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
	<span style="color: #000088;">$_SESSION</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'lastException'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$exception</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'An error happened :'</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'Error : '</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$exception</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'StackTrace : '</span><span style="color: #339933;">.</span><a href="http://www.php.net/debug_backtrace"><span style="color: #990000;">debug_backtrace</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'Informations diverses : '</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">.</span><a href="http://www.php.net/print_r"><span style="color: #990000;">print_r</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$GLOBALS</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<a href="http://www.php.net/mail"><span style="color: #990000;">mail</span></a><span style="color: #009900;">&#40;</span>
	        <span style="color: #0000ff;">'email@company.com'</span><span style="color: #339933;">,</span>
	        <span style="color: #0000ff;">'MyProject : Error : '</span><span style="color: #339933;">.</span><span style="color: #000088;">$exception</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFile</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">.</span><span style="color: #000088;">$exception</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
	        <span style="color: #000088;">$message</span>
	<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000088;">$target</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$exception</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getFile</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">':'</span><span style="color: #339933;">.</span><span style="color: #000088;">$exception</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getLine</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span> <span style="color: #000088;">$engine</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'bug'</span><span style="color: #009900;">&#93;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$engine</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'bug'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
		Logger<span style="color: #339933;">::</span><a href="http://www.php.net/log"><span style="color: #990000;">log</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/array"><span style="color: #990000;">array</span></a><span style="color: #009900;">&#40;</span>
			<span style="color: #0000ff;">'message'</span>		<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'An exception was thrown'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'type'</span>			<span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'error/exception'</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'target'</span>		<span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/substr"><span style="color: #990000;">substr</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$target</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">-</span><a href="http://www.php.net/min"><span style="color: #990000;">min</span></a><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">250</span><span style="color: #339933;">,</span> <a href="http://www.php.net/strlen"><span style="color: #990000;">strlen</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$target</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'data'</span>			<span style="color: #339933;">=&gt;</span> <a href="http://www.php.net/serialize"><span style="color: #990000;">serialize</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$GLOBALS</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
			<span style="color: #0000ff;">'level'</span>			<span style="color: #339933;">=&gt;</span> Logger<span style="color: #339933;">::</span><span style="color: #004000;">CRITICAL</span>
		<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>debug_backtrace requires PHP 4.3 and set_error_handler only supports error types since PHP 5.0. So, if you plan on using this on a PHP 4.X host, you have to make sure your code doesn&#8217;t throw E_NOTICE errors. My code is never E_NOTICE error safe.</p>
]]></content:encoded>
			<wfw:commentRss>http://florent.clairambault.fr/automatic-php-error-reporting/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Database Caching 1/39 queries in 0.016 seconds using disk: basic
Object Caching 1283/1362 objects using disk: basic

Served from: florent.clairambault.fr @ 2012-02-07 10:16:13 -->
