phil88 Posted April 7, 2009 Share Posted April 7, 2009 I need to use memory_get_peak_usage(), but it's only available in PHP versions > 5.2.0 and I have 5.0.4. I can't use memory_get_usage() either because PHP wasn't compiled with --enable-memory-limit. So, because of this...I'm stuck. Does anybody know of an alternative implementation of either function that would work on my set up? There's no way for me to upgrade PHP or recompile it, I'm stuck with this environment unfortunately. Bit of useful info; PHP 5.0.4, not compiled with --enable-memory-limit Windows XP I'm guessing that I'm going to need to use exec(), but the examples in the comments on php.net don't seem to be working. Quote Link to comment https://forums.phpfreaks.com/topic/152987-solved-memory_get_peak_usage-alternative/ Share on other sites More sharing options...
JonnoTheDev Posted April 7, 2009 Share Posted April 7, 2009 yes you will. the following works (from php.net) <?php if( !function_exists('memory_get_usage') ) { function memory_get_usage() { if ( substr(PHP_OS,0,3) == 'WIN') { if ( substr( PHP_OS, 0, 3 ) == 'WIN' ) { $output = array(); exec( 'tasklist /FI "PID eq ' . getmypid() . '" /FO LIST', $output ); return preg_replace( '/[\D]/', '', $output[5] ) * 1024; } } else { $pid = getmypid(); exec("ps -eo%mem,rss,pid | grep $pid", $output); $output = explode(" ", $output[0]); //rss is given in 1024 byte units return $output[1] * 1024; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/152987-solved-memory_get_peak_usage-alternative/#findComment-803683 Share on other sites More sharing options...
phil88 Posted April 7, 2009 Author Share Posted April 7, 2009 Either I have magical scripts, or it doesn't work on my set up. It always returns 0. Edit: I tried running the exec(...) stuff from a batch file, and it said: 'tasklist' is not recognised as an internal or external command, operable program or batch file. Is this because I have XP Home as opposed to Pro or a server edition? Quote Link to comment https://forums.phpfreaks.com/topic/152987-solved-memory_get_peak_usage-alternative/#findComment-803688 Share on other sites More sharing options...
phil88 Posted April 7, 2009 Author Share Posted April 7, 2009 Ok, I managed to copy tasklist.exe off of another PC (that had XP Pro) and put it in my system32 folder and now it works Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/152987-solved-memory_get_peak_usage-alternative/#findComment-803695 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.