473,654 Members | 3,096 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Info about php script being executed from within function.

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("functi ons.php");

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

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

postprocess.phh p (php_auto_prepe nd)
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_TRANSLATE D"] point to index.php

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

--
Sandman[.net]
Aug 25 '05 #1
6 1324
*** Sandman wrote/escribió (Thu, 25 Aug 2005 14:01:05 +0200):
The constant __FILE__ points to the file in which gauge was *defined* (i.e.
init.php) and superglobals like $_SERVER["PATH_TRANSLATE D"] point to index.php

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


From the constant __FUNCTION__, I presume:

http://es2.php.net/manual/en/languag...predefined.php
--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Aug 25 '05 #2
Sandman wrote:
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.

<snip>

Don't reinvent the wheels <http://in.php.net/apd> Also, you can
*never* get reliable results with microtime and (pure) PHP based
benchmarks (except using the hooks like APD).

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com

Aug 25 '05 #3
In article <xj************ *************** **@40tude.net>,
Alvaro G Vicario <al************ ******@telecomp uter.com> wrote:
*** Sandman wrote/escribió (Thu, 25 Aug 2005 14:01:05 +0200):
The constant __FILE__ points to the file in which gauge was *defined* (i.e.
init.php) and superglobals like $_SERVER["PATH_TRANSLATE D"] point to
index.php

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


From the constant __FUNCTION__, I presume:

http://es2.php.net/manual/en/languag...predefined.php


Eh? The constant __FUNCTION__ contains the name of the current function, which
when used inside of gauge() naturally returns "gauge".

--
Sandman[.net]
Aug 25 '05 #4
debug_backtrace () should give you what you need.

Aug 25 '05 #5
In article <11************ **********@g49g 2000cwa.googleg roups.com>,
"Chung Leong" <ch***********@ hotmail.com> wrote:
debug_backtrace () should give you what you need.


Yes, it's exactly what I wanted. Thanks a lot!

--
Sandman[.net]
Aug 25 '05 #6
*** Sandman wrote/escribió (Thu, 25 Aug 2005 19:21:31 +0200):
http://es2.php.net/manual/en/languag...predefined.php


Eh? The constant __FUNCTION__ contains the name of the current function, which
when used inside of gauge() naturally returns "gauge".


Hmmm... Yes, you're right. You should pass its value on each call or use a
global variable.

As they've already mentioned, debug_backtrace () is a better option in your
case.
--
-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group
--
Aug 26 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
24069
by: vishal | last post by:
Hi, I am writing my first script to execute a Oracle procedure through a unix script. Could you tell me how do I do error handling here? How do I know in my script if the procedure executed successfully or failed? Thanks #!/usr/bin/ksh sqlplus user/password@name <<EOC set time on
8
4218
by: Johnny Knoxville | last post by:
I've added a favicon to my site (http://lazyape.filetap.com/) which works fine if you add the site to favourites the normal way, but I have some JavaScript code on a couple of pages with a link, which when you click it bookmarks the site (much easier). The favicon is never saved if the site is bookmarked this way. Does anyone have any ideas how to fix this?? This is the code: <script language="JavaScript">
2
3098
by: Juggler | last post by:
Hi, I have a shell script which takes three arguments, how can I call this script from within a C++ program. I am new to C++ programming and not sure how to accomplish this. I tried using system() call but could make it work, must be doing something wrong. Appreciate any help in this regard. Thanks, Juggler
1
2596
by: ebrandmark | last post by:
I am trying to load a SCRIPT SRC tag that will result in a document.write into a specific location in my web page but not call for the SCRIPT SRC until the end of the page (so as not to delay the page). The DEFER method won't work because the document.write just starts a new page. I was hoping to leave a DIV where the result should end up. Then at the end of the page create a child of this DIV or another DIV that lays on top of this...
6
3941
by: Bart Schelkens | last post by:
Hi, how can I execute a piece of Java-script after a piece of vb-net-code has been executed? Thx
5
2399
by: jeet_sen | last post by:
Hi, My external javascript test.js contains a variable definition var a = "Hello,world!!"; I dynamically loaded the script test.js using the following fucntion: function loadScript(url) { var e = document.createElement("script"); e.src = url; e.type="text/javascript";
3
2957
by: Water Cooler v2 | last post by:
Questions: 1. Can there be more than a single script block in a given HEAD tag? 2. Can there be more than a single script block in a given BODY tag? To test, I tried the following code. None of the script gets executed. Can someone please give me a direction as to what I may be missing? Thanks.
2
2617
by: ethandbrown | last post by:
Hi All-- I'm a bit stymied here. I need to display arbitrary HTML obtained through AJAX. The problem is when a <script> block is encountered one can't use innerHTML to set the content, because the <script> block won't be evaluated. Googling around, a found the createContextualFragment() solution which does execute script code. The following, for example, works:
17
34701
by: PJ | last post by:
Greetings... I have stumbled upon a small problem. I use Ajax to retrieve part of a page I need to update. I update a DIV element with the HTML contents I get from another page. It works fine. However the HTML have a SCRIPT tag that the browser should process, but
0
8372
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8285
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8475
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8591
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5621
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4149
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1915
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.