<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Log memory usage using declare and ticks in PHP</title>
	<atom:link href="http://www.davedevelopment.co.uk/2008/05/12/log-memory-usage-using-declare-and-ticks-in-php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.davedevelopment.co.uk/2008/05/12/log-memory-usage-using-declare-and-ticks-in-php/</link>
	<description>Dave Marshall</description>
	<pubDate>Mon, 08 Sep 2008 09:52:24 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.1</generator>
		<item>
		<title>By: Chris</title>
		<link>http://www.davedevelopment.co.uk/2008/05/12/log-memory-usage-using-declare-and-ticks-in-php/#comment-52732</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Mon, 26 May 2008 01:02:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.davedevelopment.co.uk/?p=59#comment-52732</guid>
		<description>Hi Dave,

My example was to show that if you keep the memory usage in an array (which is stored *in memory*) - you get wrong results.</description>
		<content:encoded><![CDATA[<p>Hi Dave,</p>
<p>My example was to show that if you keep the memory usage in an array (which is stored *in memory*) - you get wrong results.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: daveyboy</title>
		<link>http://www.davedevelopment.co.uk/2008/05/12/log-memory-usage-using-declare-and-ticks-in-php/#comment-52091</link>
		<dc:creator>daveyboy</dc:creator>
		<pubDate>Tue, 20 May 2008 07:34:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.davedevelopment.co.uk/?p=59#comment-52091</guid>
		<description>@Chris - Not really sure I follow you're example. I agree logging to a file would be better for accuracy, but would slow your application down greatly, hence the 'insert your logging code here'.</description>
		<content:encoded><![CDATA[<p>@Chris - Not really sure I follow you&#8217;re example. I agree logging to a file would be better for accuracy, but would slow your application down greatly, hence the &#8216;insert your logging code here&#8217;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chris</title>
		<link>http://www.davedevelopment.co.uk/2008/05/12/log-memory-usage-using-declare-and-ticks-in-php/#comment-52074</link>
		<dc:creator>Chris</dc:creator>
		<pubDate>Tue, 20 May 2008 03:45:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.davedevelopment.co.uk/?p=59#comment-52074</guid>
		<description>You're better off logging the backtrace etc to a file, otherwise you are using a global variable which takes up memory itself.


&#60;?php

echo "at line " . __LINE__ . " memory is " . memory_get_usage(true) . "\n";

$log = array();
for ($i = 0; $i  microtime(true),
			'memory' =&#62; memory_get_usage(true),
			'file' =&#62; __FILE__
		);
}

echo "at line " . __LINE__ . " memory is " . memory_get_usage(true) . "\n";</description>
		<content:encoded><![CDATA[<p>You&#8217;re better off logging the backtrace etc to a file, otherwise you are using a global variable which takes up memory itself.</p>
<p>&lt;?php</p>
<p>echo &#8220;at line &#8221; . __LINE__ . &#8221; memory is &#8221; . memory_get_usage(true) . &#8220;\n&#8221;;</p>
<p>$log = array();<br />
for ($i = 0; $i  microtime(true),<br />
			&#8216;memory&#8217; =&gt; memory_get_usage(true),<br />
			&#8216;file&#8217; =&gt; __FILE__<br />
		);<br />
}</p>
<p>echo &#8220;at line &#8221; . __LINE__ . &#8221; memory is &#8221; . memory_get_usage(true) . &#8220;\n&#8221;;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Logging PHP script memory usage &#124; PHP Readings</title>
		<link>http://www.davedevelopment.co.uk/2008/05/12/log-memory-usage-using-declare-and-ticks-in-php/#comment-51984</link>
		<dc:creator>Logging PHP script memory usage &#124; PHP Readings</dc:creator>
		<pubDate>Mon, 19 May 2008 09:55:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.davedevelopment.co.uk/?p=59#comment-51984</guid>
		<description>[...] Marshall posted article about php script memory usage logging. Memory logging is important because you may know haw many [...]</description>
		<content:encoded><![CDATA[<p>[...] Marshall posted article about php script memory usage logging. Memory logging is important because you may know haw many [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Konr Ness</title>
		<link>http://www.davedevelopment.co.uk/2008/05/12/log-memory-usage-using-declare-and-ticks-in-php/#comment-51716</link>
		<dc:creator>Konr Ness</dc:creator>
		<pubDate>Fri, 16 May 2008 15:52:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.davedevelopment.co.uk/?p=59#comment-51716</guid>
		<description>Very timely article. Thank you. I was debugging a large online store that was using 25+MB of memory on the first load. I modified it slightly to not use sessions, and also show which file and what line of the file was being run at each tick:

$memory_usage = array();
$start_time = microtime(true);
function log_memory(){
    global $memory_usage;
    global $start_time;
    $stacktrace = debug_backtrace();
    $memory_usage[] = array(
        'time' =&#62; microtime(true) - $start_time,
        'memory' =&#62; memory_get_usage(),
        'file' =&#62; $stacktrace[1]['file'] . ':' . $stacktrace[1]['line']
    );
}

declare(ticks = 100);
register_tick_function('log_memory');</description>
		<content:encoded><![CDATA[<p>Very timely article. Thank you. I was debugging a large online store that was using 25+MB of memory on the first load. I modified it slightly to not use sessions, and also show which file and what line of the file was being run at each tick:</p>
<p>$memory_usage = array();<br />
$start_time = microtime(true);<br />
function log_memory(){<br />
    global $memory_usage;<br />
    global $start_time;<br />
    $stacktrace = debug_backtrace();<br />
    $memory_usage[] = array(<br />
        &#8216;time&#8217; =&gt; microtime(true) - $start_time,<br />
        &#8216;memory&#8217; =&gt; memory_get_usage(),<br />
        &#8216;file&#8217; =&gt; $stacktrace[1]['file'] . &#8216;:&#8217; . $stacktrace[1]['line']<br />
    );<br />
}</p>
<p>declare(ticks = 100);<br />
register_tick_function(&#8217;log_memory&#8217;);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: EllisGL</title>
		<link>http://www.davedevelopment.co.uk/2008/05/12/log-memory-usage-using-declare-and-ticks-in-php/#comment-51493</link>
		<dc:creator>EllisGL</dc:creator>
		<pubDate>Wed, 14 May 2008 19:54:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.davedevelopment.co.uk/?p=59#comment-51493</guid>
		<description>Watch out, register_tick_function will crashed on threaded servers. Also I haven't been able to get it to work in a windows environment yet.</description>
		<content:encoded><![CDATA[<p>Watch out, register_tick_function will crashed on threaded servers. Also I haven&#8217;t been able to get it to work in a windows environment yet.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Link Bundle - May 14 &#124; franzone.com</title>
		<link>http://www.davedevelopment.co.uk/2008/05/12/log-memory-usage-using-declare-and-ticks-in-php/#comment-51475</link>
		<dc:creator>Link Bundle - May 14 &#124; franzone.com</dc:creator>
		<pubDate>Wed, 14 May 2008 16:49:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.davedevelopment.co.uk/?p=59#comment-51475</guid>
		<description>[...] Bundle - May 14  Author : Jonathan Franzone No Comments   Log memory usage using declare and ticks in PHP Dave Marshall, a web developer living in Hull, England, share a really quick and simple trick to [...]</description>
		<content:encoded><![CDATA[<p>[...] Bundle - May 14  Author : Jonathan Franzone No Comments   Log memory usage using declare and ticks in PHP Dave Marshall, a web developer living in Hull, England, share a really quick and simple trick to [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: daveyboy</title>
		<link>http://www.davedevelopment.co.uk/2008/05/12/log-memory-usage-using-declare-and-ticks-in-php/#comment-51467</link>
		<dc:creator>daveyboy</dc:creator>
		<pubDate>Wed, 14 May 2008 16:09:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.davedevelopment.co.uk/?p=59#comment-51467</guid>
		<description>Thanks Mathieu, I've updated the post to recommend your comment.</description>
		<content:encoded><![CDATA[<p>Thanks Mathieu, I&#8217;ve updated the post to recommend your comment.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mathieu Kooiman</title>
		<link>http://www.davedevelopment.co.uk/2008/05/12/log-memory-usage-using-declare-and-ticks-in-php/#comment-51457</link>
		<dc:creator>Mathieu Kooiman</dc:creator>
		<pubDate>Wed, 14 May 2008 14:53:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.davedevelopment.co.uk/?p=59#comment-51457</guid>
		<description>When you use an xdebug trace instead of profiling you'll get the memory usage per entry in the trace.

Tad more work to go through, but probably more reliable than ticks..

http://xdebug.org/docs/execution_trace</description>
		<content:encoded><![CDATA[<p>When you use an xdebug trace instead of profiling you&#8217;ll get the memory usage per entry in the trace.</p>
<p>Tad more work to go through, but probably more reliable than ticks..</p>
<p><a href="http://xdebug.org/docs/execution_trace" rel="nofollow">http://xdebug.org/docs/execution_trace</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
