This is a tough one.

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Thu Jul 21, 2005 9:46 am    Post subject: This is a tough one. Reply with quote

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 View user's profile Send private message Visit poster's website
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Thu Jul 21, 2005 2:38 pm    Post subject: Re: This is a tough one. Reply with quote

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 View user's profile Send private message Send e-mail
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Thu Jul 21, 2005 5:59 pm    Post subject: Reply with quote

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 View user's profile Send private message Visit poster's website
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Fri Jul 22, 2005 4:50 pm    Post subject: Reply with quote

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 View user's profile Send private message Send e-mail
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3752
Location: USA, GA

PostPosted: Fri Jul 22, 2005 4:51 pm    Post subject: Reply with quote

Ok , I will use your code for the PHP script. Thank You!

Sincerely , TRUSTpunk
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group