Jump to content


Photo

get the size of the output of a php file?


  • Please log in to reply
2 replies to this topic

#1 colfaxrev

colfaxrev
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 27 October 2006 - 10:56 PM

Is there a way of getting the final size in bytes of the output of a php file?

i have a separate php file that is doing the following...

print "filesize[" . filesize('roro3.flv') . "]";

which outputs...
filesize[18492343]

so that works fine...

I want to get the FINAL size in bytes for the output of a php file... i tried this (which i was sure wouldn't work)

print "filesize[" . filesize('tracking.php?action=show') . "]";

You can see that file for youself here...
http://triotalentage...php?action=show

but that code prints out this...

filesize[]

i also tried to use readfile() but that didn't seem to work....
is there anyway to do this?

thanks!

#2 ksteuber

ksteuber
  • Members
  • PipPipPip
  • Advanced Member
  • 32 posts
  • LocationCalifornia, USA

Posted 28 October 2006 - 03:23 AM

if you are trying to find the size of the output of a page that will always be a constant size you can probably do this:

$site = file_get_contents('http://www.mywebsite.com/tracking.php?action=show');
print "filesize[" . strlen($site) . "]";

I believe that "filesize" only works for local files, so "filesize('http://www.mywebsite...php?action=show')" wouldn't work. Since 'http://www.mywebsite...php?action=show' is clearly not local.

Also, if what you were attempting to do was to retrieve the file locally, the script would be looking for a file named 'tracking.php?action=show', not a file named 'tracking.php'.

(Also retreiving a php file locally gets the code of the file, not the output. ie: filesize("helloworld.php") would get the length of "<?php echo 'Hello World'; ?>" rather than the length of "Hello World")

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 28 October 2006 - 10:01 AM

::test1.php::
<?php

for($i=0; $i<250; $i++) echo 'x';

?>

::test2.php::
<?php
  
  ob_start();
  include('test1.php');
  echo strlen(ob_get_clean());   // --> 250
  
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users