By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,628 Members | 1,175 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,628 IT Pros & Developers. It's quick & easy.

What is that function called again? Time taken to do script.

P: n/a
Hi,

I recall a function that would tell me how long it took to generate an
output.
But for the life of me I cannot remember it.

Dow anybody know it? Or do I have to write something myself, (using time?).

Sims
Jul 17 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Sims wrote:
Hi,

I recall a function that would tell me how long it took to generate an
output.
But for the life of me I cannot remember it.

Dow anybody know it? Or do I have to write something myself, (using
time?).

Sims

Maybe there is a function I don't know about, but I have seen most people do
this by running microtime() at the beginning and end of the script, and
subtracting. I think its useless for your average script which takes less
than 2 seconds, because microtime is in no way precise.
Jul 17 '05 #2

P: n/a
"Sims" <si*********@hotmail.com> wrote:
I recall a function that would tell me how long it took to generate an
output.
But for the life of me I cannot remember it.

Dow anybody know it? Or do I have to write something myself, (using
time?).


You can use microtime(). Example of what you're after in the manual:
http://uk.php.net/manual/en/function.microtime.php

HTH;
JOn
Jul 17 '05 #3

P: n/a

"Jon Kraft" <jo*@jonux.co.uk> wrote in message
news:Xn**************************@130.133.1.4...
"Sims" <si*********@hotmail.com> wrote:
I recall a function that would tell me how long it took to generate an
output.
But for the life of me I cannot remember it.

Dow anybody know it? Or do I have to write something myself, (using
time?).


You can use microtime(). Example of what you're after in the manual:
http://uk.php.net/manual/en/function.microtime.php


Thanks all, I will use microtime, I just want to make sure that the scrip
does not take too long.

But on the same subject, what is "too long" how small should I keep my
script in KB for it to be 'acceptable?
I saw an article that a page should not take 'more than 30 seconds', surely
30 seconds is far too long for one page.

Regards.

Sims.
Jul 17 '05 #4

P: n/a
On Mon, 19 Apr 2004 12:56:00 +0100, "Sims" <si*********@hotmail.com>
wrote:

"Jon Kraft" <jo*@jonux.co.uk> wrote in message
news:Xn**************************@130.133.1.4.. .
"Sims" <si*********@hotmail.com> wrote:
> I recall a function that would tell me how long it took to generate an
> output.
> But for the life of me I cannot remember it.
>
> Dow anybody know it? Or do I have to write something myself, (using
> time?).
You can use microtime(). Example of what you're after in the manual:
http://uk.php.net/manual/en/function.microtime.php


Thanks all, I will use microtime, I just want to make sure that the scrip
does not take too long.

But on the same subject, what is "too long" how small should I keep my
script in KB for it to be 'acceptable?


You can't really infer a correlation between the filesize of the
script and its execution time. A script that performs a lot of
database queries or fetches data from some other server will/may take
longer than one that does not.
I saw an article that a page should not take 'more than 30 seconds', surely
30 seconds is far too long for one page.


If you are developing an intranet page that generates a complex report
and the users know that it will take that long, you can probably get
away with it. On a shared server, the server owners may not like your
script taking up that much CPU time, and users may not wait 30
seconds.

It really depends on the situation.

--
David ( @priz.co.uk )
Jul 17 '05 #5

P: n/a
But on the same subject, what is "too long" how small should I keep my
script in KB for it to be 'acceptable?
You can't really infer a correlation between the filesize of the
script and its execution time. A script that performs a lot of
database queries or fetches data from some other server will/may take
longer than one that does not.


Sorry by file size I wanted to say the packet been sent to the browser/user,
not the size of the script.
Because yes, sending a file bigger than 100/200k would not be practical,
(and more importantly if it can be monitored then it useful to know).

How would I calculate/estimate the size of the packet sent?
I saw an article that a page should not take 'more than 30 seconds', surely30 seconds is far too long for one page.


If you are developing an intranet page that generates a complex report
and the users know that it will take that long, you can probably get
away with it. On a shared server, the server owners may not like your
script taking up that much CPU time, and users may not wait 30
seconds.

It really depends on the situation.


Of course, but knowing how long it takes might also be useful.
If I do not want *any* page to be more than x seconds then I could, (try
and), monitor those pages.

Sims
Jul 17 '05 #6

P: n/a
Sims wrote:
Sorry by file size I wanted to say the packet been sent to the browser/user,
not the size of the script.
Because yes, sending a file bigger than 100/200k would not be practical,
(and more importantly if it can be monitored then it useful to know).

How would I calculate/estimate the size of the packet sent?


PHP is server-side - the file size of the PHP script has absolutely no
correlation to the amount of data sent to the user's browser. You could
easily write a tiny PHP script that could send megabytes of data to a
user's browser.

eg.
<?php
for( $i=0; $i<1000000000; $i++ ) {
echo "Here's some data<br>";
}
?>

Ultimately, the size of what the user will receive in their browser
depends on the

1) The size of the generated HTML
2) embedded/linked content within that HTML file - images, flash, movies
etc.

So are asking how using PHP you can calculate the total of #1 & #2 for a
given script output?
Jul 17 '05 #7

P: n/a
>
PHP is server-side - the file size of the PHP script has absolutely no
correlation to the amount of data sent to the user's browser. You could
easily write a tiny PHP script that could send megabytes of data to a
user's browser.

eg.
<?php
for( $i=0; $i<1000000000; $i++ ) {
echo "Here's some data<br>";
}
?>

Ultimately, the size of what the user will receive in their browser
depends on the

1) The size of the generated HTML
2) embedded/linked content within that HTML file - images, flash, movies
etc.

So are asking how using PHP you can calculate the total of #1 & #2 for a
given script output?


But as a server side operation php create something that will be sent to the
browser, (HTML page, links etc).
So yes I would be curious to see the size of what is sent, (including
images).

But I realise that it is not an easy task but using

<?php
for( $I=0; $i<1000000000; $i++ ) {
echo "Here's some data<br>";
}
?>

I can guess how big the final output will be, (and add the size of images).

With the size I could then make an educated guess if the pages is too big
and needs to be trimmed.

Sims
Jul 17 '05 #8

P: n/a
"Sims" <si*********@hotmail.com> wrote in message
news:c6************@ID-162430.news.uni-berlin.de...

PHP is server-side - the file size of the PHP script has absolutely no
correlation to the amount of data sent to the user's browser. You could
easily write a tiny PHP script that could send megabytes of data to a
user's browser.

eg.
<?php
for( $i=0; $i<1000000000; $i++ ) {
echo "Here's some data<br>";
}
?>

Ultimately, the size of what the user will receive in their browser
depends on the

1) The size of the generated HTML
2) embedded/linked content within that HTML file - images, flash, movies
etc.

So are asking how using PHP you can calculate the total of #1 & #2 for a
given script output?
But as a server side operation php create something that will be sent to

the browser, (HTML page, links etc).
So yes I would be curious to see the size of what is sent, (including
images).

But I realise that it is not an easy task but using

<?php
for( $I=0; $i<1000000000; $i++ ) {
echo "Here's some data<br>";
}
?>

I can guess how big the final output will be, (and add the size of images).
With the size I could then make an educated guess if the pages is too big
and needs to be trimmed.

Sims


Use output buffering and use ob_get_length to get the size of the data being
streamed. Note that your images are actually separate retrieves. Most like
you are including <img> tags. Right? As such, you will output a stream of
html and the browser will then make an additional request to get the actual
image. You could determine what images will be requested as you build the
html and then get their sizes and add them to the size of the html you find
in the output buffer.

See http://us2.php.net/manual/en/ref.outcontrol.php for more info on output
buffering/control.

- Virgil
Jul 17 '05 #9

P: n/a
On Mon, 19 Apr 2004 15:33:20 +0100, "Sims" <si*********@hotmail.com>
wrote:
How would I calculate/estimate the size of the packet sent?


Opera has an "Info" panel that displays the size of the requested
resource and also the total size of all the inline elements (images,
stylesheets, etc).
If you are developing an intranet page that generates a complex report
and the users know that it will take that long, you can probably get
away with it. On a shared server, the server owners may not like your
script taking up that much CPU time, and users may not wait 30
seconds.


Of course, but knowing how long it takes might also be useful.
If I do not want *any* page to be more than x seconds then I could, (try
and), monitor those pages.


If your page does a lot of queries or other processing then it's
probably useful to check how long it takes.

--
David ( @priz.co.uk )
Jul 17 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.