[PHP] Determining system resources

2004-11-04 Thread Robin Getz
I have been unable to find a php function to determine available system
memory (physical and swap)?
Right now I am using something like:
=
# ensure there is enough free memory for the download
$free = shell_exec('free -b'); $i=0; while ( $i != strlen($free) ) {
i = strlen($free);
free = str_replace('  ',' ',$free); 
}
$free = str_replace(\n,'',$free);
$freeArray = explode(' ',$free);
$total_free = $freeArray[9] + $freeArray[18];
==
Does anyone have any ideas that could be used on all OSes? i.e. Without 
shell_exec()?

Thanks in advance.
-Robin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Determining system resources

2004-11-04 Thread Greg Donald
On Thu, 04 Nov 2004 08:25:19 -0800, Robin Getz
[EMAIL PROTECTED] wrote:
 I have been unable to find a php function to determine available system
 memory (physical and swap)?

 php -r system('free -m');
 total   used   free sharedbuffers cached
Mem:   249246  2  0  4 86
-/+ buffers/cache:154 94
Swap:  486 12473

The system has to support whatever memory command you use.

*nix: free
windoze: mem


-- 
Greg Donald
Zend Certified Engineer
http://gdconsultants.com/
http://destiney.com/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Determining system resources

2004-11-04 Thread Francisco M. Marzoa Alonso
Greetings Robin,
As far as you cannot lock another processes in the system, so this will 
not give you the security that the resources will not change -and 
probably they'll do it- while you're trying to download that file.

Best regards,
Robin Getz wrote:
I have been unable to find a php function to determine available system
memory (physical and swap)?
Right now I am using something like:
=
# ensure there is enough free memory for the download
$free = shell_exec('free -b'); $i=0; while ( $i != strlen($free) ) {
i = strlen($free);
free = str_replace('  ',' ',$free);   
}
$free = str_replace(\n,'',$free);
$freeArray = explode(' ',$free);
$total_free = $freeArray[9] + $freeArray[18];
==

Does anyone have any ideas that could be used on all OSes? i.e. 
Without shell_exec()?

Thanks in advance.
-Robin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Determining system resources

2004-11-04 Thread Robin Getz
Francisco M. Marzoa Alonso [EMAIL PROTECTED] wrote:
As far as you cannot lock another processes in the system, so this will 
not give you the security that the resources will not change -and probably 
they'll do it- while you're trying to download that file.
Yes, I understand, but not to know even if you are in the right order of 
magnitude, is kind of scary isn't it?

For example on my system, I have 1 Gig of physical memory, and 3Gig of 
swap. If I end up with only 512k free - something is very wrong, and I 
should disallow functions I know that eat up memory. There is a low 
probability that multiple connections will pass the test, and then consume 
the memory, so yes this is not 100% coverage.

Maybe what I am seeing is actually a bug in the way that readfile() handles 
low memory situations. If there is not enough memory for internal functions 
to run, they should error, not crash your system.

I assume that the way the converstation is moved is that there is not a way 
to see what free system memory is, without calling a command line function 
(free or mem).

-Robin 

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php