I use this function to produce a small speed test in my pages since I run my website from my home computers.
<?php
ob_start();
$StartTime=microtime(1);
?>
.. webpage data goes here ..
<?php
// footer?
printf("%s seconds to produce (%skb/sec)",
microtime(1)-$StartTime,
Round((ob_get_length()/(microtime(1)-$StartTime))/1024));
ob_end_flush();
?>
Note: don't forget the "speed" depends on how quick the content is actually generated and not on the speed the data is sent to the client..
However it would be good to see such function to get the real speed. :)
Nitrogen.
PHP.mk документација
ob_get_length
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
Патека
function.ob-get-length.php
Локална патека за оваа страница.
Извор
php.net/manual/en
Оригиналниот HTML се реупотребува и локално се стилизира.
Режим
Прокси + превод во позадина
Кодовите, табелите и белешките остануваат читливи во истиот тек.
Референца
function.ob-get-length.php
ob_get_length
Референца за `function.ob-get-length.php` со подобрена типографија и навигација.
ob_get_length
(PHP 4 >= 4.0.2, PHP 5, PHP 7, PHP 8)
ob_get_length — (PHP 4 >= 4.0.2, PHP 5, PHP 7, PHP 8)
Параметри
Оваа функција нема параметри.
Вратени вредности
Ова ќе ја врати должината на содржината во баферот за излез, во бајти. false Враќа должина на содржината на баферот за излез, во бајти, или
Примери
Пример #1 Едноставен ob_get_length() example
<?php
ob_start();
echo "Hello ";
$len1 = ob_get_length();
echo "World";
$len2 = ob_get_length();
ob_end_clean();
echo $len1 . ", " . $len2;
?>Пример #1 Пример што покажува затворачка ознака што го опфаќа последниот нов ред
6, 11
Види Исто така
- ob_start() - Вклучи баферирање на излезот
- ob_get_contents() - Врати ги содржините на излезниот бафер
Белешки од корисници 3 белешки
Испринтај ги сите преостанати податоци на покажувач на gz-датотека ¶
пред 17 години
ако нема активно баферирање. ¶
20 години пред
There is a work-around for the situation you need to get length of the gz-ed buffer.
ob_start();
ob_start('ob_gzhandler');
... output the page content...
ob_end_flush(); // The ob_gzhandler one
header('Content-Length: '.ob_get_length());
ob_end_flush(); // The main one
more info at http://www.edginet.org/techie/website/http.html
jodybrabec at gmail dot com ¶
пред 18 години
If you don't buffer your output, it doesn't seem like it would be possible for a web server to output a Content-Length header. For static files it can check the filesize, but for dynamic files that send output a little by little there is no way to know how many bytes it is going to output. And the headers have to be sent before a single byte is output.
Also if you're wondering why the Content-Length is important, the browser doesn't close the connection as long as the script is running. So if you register time consuming shutdown functions, the browser will still 'spin' waiting for more content until they complete. (I'm not sure this happens under all conditions, but I am certain the sending the Content-Length always prevents this.)
You might take note that this manual page does not currently output any Content-Length header.
Alternatively using mb_strlen($output, 'latin1') seems to work to determine bytes in a string. strlen may or may not depending on if it has been set up as a multibyte or not.