Right I understand the problem I have been experiencing now. 1) Functions that return something do not work 2) APC and ticks do not mix - I needed to restart the web server to get it to work If you have apc installed, try making changes to your src. Ie - adding new calls to different functions. They aren't invoked on ticks. I don't think these ticks can be relied upon - a neat idea but they don't seem to be implemented right yet. Scott -----Original Message----- From: Shawn McKenzie [mailto:nospam@xxxxxxxxxxxxx] Sent: Friday, February 08, 2008 6:34 AM To: php-general@xxxxxxxxxxxxx Subject: Re: Re: Profiling with register_tick_function / declare McNaught, Scott wrote: > Hi Shawn, > > Thanks for the reply. I am using php5+ only, so I'm quite sure that passing > the object by reference like that is done automatically. > > Aren't all objects are automatically passed by reference in php5, so > therefore & is deprecated? I tested your suggestion anyway, and it appeared > to make no difference. > > The problem is to do with the scope that the "declare" directive affects. > > Cheers anyway, > > Scott > > -----Original Message----- > From: Shawn McKenzie [mailto:nospam@xxxxxxxxxxxxx] > Sent: Friday, February 08, 2008 5:43 AM > To: php-general@xxxxxxxxxxxxx > Subject: Re: Profiling with register_tick_function / declare > > McNaught, Scott wrote: >> Hi there, >> >> >> >> Is it possible to make the declare(ticks=1) statement apply to *all* >> functions executed in a php script, regardless of scope? >> >> >> >> I wish to write a profiler script to basically dump all the function call >> times through the execution of a script. So far, I can only get it to > work >> for functions called via global scope. >> >> >> >> My code calls only one function from the global scope, and then a whole > lot >> of functions in classes are invoked. The tick function is only invoked > once >> from calling this one global function. >> >> >> >> Here is my code: >> >> >> >> <?php >> >> declare(ticks = 1); >> >> >> >> /** >> >> * Profiler >> >> * >> >> * @version SVN: $Id$ >> >> * @author Scott McNaught >> >> */ >> >> class Profiler >> >> { >> >> protected $m_arrProfileData = array(); >> >> protected $m_strCurrentFunction = null; >> >> protected $m_iLastTime = null; >> >> >> >> /** >> >> * Begins profiling >> >> */ >> >> public function start() >> >> { >> >> $this->m_iLastTime = time(); >> >> } >> >> >> >> /** >> >> * Finishes profiling and dumps the results >> >> */ >> >> public function end() >> >> { >> >> var_dump($this->m_arrProfileData); >> >> $this->m_arrProfileData = array(); >> >> $this->m_strCurrentFunction = null; >> >> } >> >> >> >> public function tick() >> >> { >> >> $arrBacktrace = debug_backtrace(); >> >> >> >> if (!isset($arrBacktrace[1])) >> >> { >> >> return; >> >> } >> >> >> >> $strFunction = $arrBacktrace[1]['function']; >> >> >> >> if (isset($arrBacktrace[1]['class'])) >> >> { >> >> $strFunction = $arrBacktrace[1]['class'] . '::' . >> $strFunction; >> >> } >> >> >> >> $iTime = microtime(true); >> >> >> >> if (!isset($this->m_arrProfileData[$strFunction])) >> >> { >> >> $this->m_arrProfileData[$strFunction] = $iTime; >> >> } >> >> >> >> $this->m_arrProfileData[$strFunction] += $iTime - >> $this->m_iLastTime; >> >> $this->m_iLastTime = $iTime; >> >> $this->m_strCurrentFunction = $strFunction; >> >> } >> >> } >> >> >> >> $pProfiler = new Profiler(); >> >> register_tick_function($pProfiler, 'tick'), true); >> >> >> >> ?> >> >> >> >> >> >> Then from index.php. >> >> >> >> <?php >> >> >> >> if(isset($_GET['profile'])) >> >> { >> >> include('profiler.inc.php'); >> >> } >> >> >> >> function execute() >> >> { >> >> $pClass = new SomeClass(); >> >> $pClass->someFunction(); >> >> } >> >> >> >> execute(); // TICK IS CALLED FROM EXECUTING THIS >> >> >> >> ?> >> >> >> >> So a tick is made from calling execute() from global scope, and that is > it. >> I want it to tick when someFunction() is called. >> >> >> >> I would really appreciate any help that anyone can give me with this as I >> have struggled with it for a while, and there is not much documentation >> about this anywhere. >> >> This could potentially benefit a lot of people if engineered right. I am >> trying to make a profiler include file which will be able to be used with >> one line of file. >> >> >> >> This will allow people to: >> >> . Get quick profiler results on demand by adding something to the >> query string - eg - ?profile=1 >> >> . Get profile results for novices without having to mess around >> installing php binaries such as APD / zend debugger etc >> >> . Profile on demand on production servers without having to > install >> a resource intensive debugging module >> >> >> >> Any help greatly appreciated. >> >> >> >> Thanks, >> >> >> >> Scott McNaught >> >> >> >> > First off: > > register_tick_function(array(&$pProfiler, 'tick'), true); > Hmmm... Also: This works: public function someFunction() { $a++; } This does not: public function someFunction() { return $a++; } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php