Reply to Info about php script being executed from within function.

Your name:

Reply:


Posted by Sandman on 08/25/05 15:01

Ok, not sure how I should explain this, but I'll give it a try.

When a browser requests any given page from my webapp, it include()'s lots of
other smaller scripts that has functions that does various stuff. This is
probably how most of us do it.

But, to measure and keep track of performance, I am using a little function
that I call gauge() to keep control over the amount of time any given request
took on my server.

In a simplified structure, this is what happens when someone requests index.php
(init.php is always loaded first through auto_append)

init.php
function gauge($keyword){
$time = getmicrotime() # another function, that just reports fractions
# of a second
$GLOBALS["page_gauge"][] = array(
"time" => $time,
"string" => $keyword
);
}

index.php
include("functions.php");

functions.php
( do stuff )
gauge("functions loaded");

index.php (continues)
( do stuff )
gauge("stuff done");

postprocess.phhp (php_auto_prepend)
gauge("webapp done");

foreach ($GLOBALS["page_gauge"] as $g){
print "$g[string]: {$time}s\n";
}


Do you get the idea? The output of the above might be - appaering after
whatever index.php outputted - something like this:

functions loaded: 0.340s
stuff done: 1.440s
webapp done: 3.340s


So, when "webapp done" was invoked, the page had taken 3.34s to execute


THE QUESTION

Ok, here comes the question! I would very much want the gauge() function to
save information about the script that invoked it, so I oculd make the output
like this:

functions.php - functions loaded: 0.340s
index.php - stuff done: 1.440s
postprocess.php - webapp done: 3.340s


For troubleshooting reasons of course.

The constant __FILE__ points to the file in which gauge was *defined* (i.e.
init.php) and superglobals like $_SERVER["PATH_TRANSLATED"] point to index.php

Anyone knows how to find out what file called on a function?

--
Sandman[.net]

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация