Can you check a random folders size?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
heiatufte
Forum Newbie
Posts: 18
Joined: Wed Mar 02, 2005 3:45 pm
Location: AA, Norway

Can you check a random folders size?

Post by heiatufte »

Hi there, random stranger from the internet!!
I know the functions disk_total_space and disk_free_space can check the free and total space on a whole disk on the server, but is it possible to check the size of only a random (but specified) folder somewhere on the server?
Answers containing "yes" and an answer would be greatly appreciated! :P
Thanks,
HeiaTufte
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

yep.. and look at that.. search works: viewtopic.php?t=29681&highlight=folder+size

:P
heiatufte
Forum Newbie
Posts: 18
Joined: Wed Mar 02, 2005 3:45 pm
Location: AA, Norway

Post by heiatufte »

8O :oops:
I am very very sorry!!! Searched only php.net...forgot both searching forum and google
Will do next time! Honest!
Please don't ban me from the forum :wink:
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I only bring out the ban-stick out for spammers and porn linkers, pretty much.

You're safe. :)
heiatufte
Forum Newbie
Posts: 18
Joined: Wed Mar 02, 2005 3:45 pm
Location: AA, Norway

Post by heiatufte »

Thanks :) looks like a great forum, as you see I got a reply in like 2 minutes :D
Anyway I checked out the posts. What's recursion and stack space? Sorry for the "newbie" question but everyone's got to learn sometime :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

recursion is calling one's self.

Code: Select all

<?php

function recurseTest( $val = 0 )
{
  echo $val . &quote;\n&quote;;
  recurseTest( $val + 1 );
}

recurseTest();

?>
on my machine it'll count from 0 to 870, where php stops the recursion on it's own.

Stack space is the active memory a function uses for each call. The more recursion you have, the more memory the application requires over it's life time, as illustrated using a function shamelessly stolen from php.net and the code above modified a bit:

Code: Select all

<?php

function getMemUsage()
{
	if (function_exists('memory_get_usage'))
	{
		return memory_get_usage();
	}
	elseif ( strpos( strtolower($_SERVERї&quote;OS&quote;]), 'windows') !== false)
	{
		// Windows workaround
		$output = array();

		exec('tasklist /FI &quote;PID eq ' . getmypid() . '&quote; /FO LIST', $output);           
		return substr($outputї5], strpos($outputї5], ':') + 1);
	}
	else
	{
		return 'no value';
	}
}

function recurseTest( $val = 0 )
{
  echo $val . &quote;\t&quote; . getMemUsage() . &quote;\n&quote;;
  recurseTest( $val + 1 );
}

recurseTest();

?>

Code: Select all

0           5,284 K
1           5,312 K
2           5,312 K
3           5,312 K
4           5,312 K
5           5,316 K
6           5,316 K
7           5,316 K
8           5,320 K
9           5,324 K
10          5,324 K
11          5,324 K
12          5,328 K
13          5,328 K
14          5,328 K
15          5,332 K
16          5,332 K
17          5,332 K
18          5,332 K
19          5,336 K
20          5,344 K
21          5,344 K
22          5,348 K
23          5,348 K
24          5,348 K
25          5,352 K
26          5,352 K
27          5,352 K
28          5,352 K
29          5,356 K
30          5,356 K
If each pass through a recursive function uses a bunch of memory, you could quickly run out of memory in php.
Post Reply