View previous topic :: View next topic |
Author |
Message |
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Thu Jul 21, 2005 9:46 am Post subject: This is a tough one. |
|
|
I want to get the number of bytes that the server sent for each PHP script.
The CONTENT_LENGTH can only be used by POST & PUT requests so what I
need to do is find another way to get the bytes , im creating a log file.
Example:
Script_01.php - Processed 280 Bytes
Script_02.php - Processed 520 Bytes
Sincerely , TRUSTpunk |
|
Back to top |
|
 |
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Thu Jul 21, 2005 2:38 pm Post subject: Re: This is a tough one. |
|
|
TRUSTpunk,
CONTENT_LENGTH is sent to the script before it starts its execution so it cannot contain the size of the data you have generated by your script.
In PHP you should use the ob_start() function to monitor chunks of data that are output and compute their size.
Add this code/include it before beginning the PHP page processing (or add it in a script configured in auto_prepend_file in php.ini):
Code: |
<?php
$output_len = 0;
function callback($buffer)
{
global $output_len;
$output_len += strlen($buffer);
return $buffer;
}
ob_start("callback");
?>
|
Add to the end of the script (or add it in a script configured in auto_append_file in php.ini):
Code: |
<?php
// Flush the buffers
@ob_end_flush ();
// Now use $output_control value as you wish
echo "Output length: $output_control";
?>
|
_________________ Support Team
Aprelium - http://www.aprelium.com |
|
Back to top |
|
 |
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Thu Jul 21, 2005 5:59 pm Post subject: |
|
|
If I use output_buffering , won't that slow down my pages if their bigger than
the default buffer size which is 4096 bytes ? Is it a potential security problem
if I modified the buffer size in php.ini ? I came up with this code.
Code: |
<?php
ob_start();
?>
<HTML HERE>
<?php
$size = ob_get_length();
echo "Page Size " . $size;
?>
<?php
ob_end_flush();
?>
|
|
|
Back to top |
|
 |
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
Posted: Fri Jul 22, 2005 4:50 pm Post subject: |
|
|
TRUSTpunk,
Buffering does not slow anything. Actually PHP does internal buffering.
The code you've suggested is worse than ours because it holds everything in a buffer until the whole script is executed. Our code does not impose this constraint and the buffering will be for smaller amounts of data (and not for the whole output). _________________ Support Team
Aprelium - http://www.aprelium.com |
|
Back to top |
|
 |
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Fri Jul 22, 2005 4:51 pm Post subject: |
|
|
Ok , I will use your code for the PHP script. Thank You!
Sincerely , TRUSTpunk |
|
Back to top |
|
 |
|