Results 1 to 7 of 7

Thread: PHP script for memory usage

  1. #1
    Join Date
    Jan 2010
    Posts
    119

    PHP script for memory usage

    Hello,
    I have hosted my site and using the cpanel to control the activities and other things. Now I need to modify some of the php code to get the memory usage for the site. How can I do this? I have tried some scripts but non of them was really useful. So, if you have some of the scripts that I may use to get the memory usage, it would be great. Thank you.

  2. #2
    Join Date
    Nov 2009
    Posts
    518

    Re: PHP script for memory usage

    This is the basic script that does this job

    Code:
    <?php
    // This is only an example, the numbers below will
    // differ depending on your system
    
    echo mem_usg() . "\n"; // 36640
    
    $a = str_repeat("Hello", 4242);
    
    echo mem_usg() . "\n"; // 57960
    
    unset($a);
    
    echo mem_usg() . "\n"; // 36744
    
    ?>

  3. #3
    Join Date
    Nov 2009
    Posts
    347

    Re: PHP script for memory usage

    To get the memory usage in KB or MB
    Code:
    <?php
        function echo_memory_usage() {
            $memory_usg = memory_get_usage(true);
           
            if ($memory_usg < 1024)
                echo $memory_usg." bytes";
            elseif ($memory_usg < 1048576)
                echo round($memory_usg/1024,2)." kilobytes";
            else
                echo round($memory_usg/1048576,2)." megabytes";
               
            echo "<br/>";
        }
    ?>

  4. #4
    Join Date
    Nov 2008
    Posts
    240

    Re: PHP script for memory usage

    Alternatively you can use this script too
    Code:
    function memory_get_usage_by_tasklist()
    {
        $otpt = array();
        exec( 'tasklist ', $otpt );
        foreach ($otpt as $value)
        {
            $execu=explode(" ",$value);
            $cnt_ex=count($execu);
            if (eregi(" ".getmypid()." Console",$value))
            {
                $mem_sz=$execu[$cnt_ex-2]." Kb";
                return $mem_sz;
            }
        }
    }
    echo memory_get_usage_by_tasklist();
    ?>

  5. #5
    Join Date
    Nov 2009
    Posts
    335

    Re: PHP script for memory usage

    Even i was find a script for doing the same job. I have found one and this works for me very well. See if this works for you

    Code:
    <?php
    function m_usage()
    {
         $processid = getmypid();
         exec("ps -o rss -p $processid", $otput);
         return $otput[1] *1024;
    }
    ?>

  6. #6
    Join Date
    Dec 2009
    Posts
    202

    Re: PHP script for memory usage

    This is what you have to do

    Code:
    memstat();
    wst_mem(10000);
    memstat();
    wst_mem(10000);
    memstat();

  7. #7
    Join Date
    Nov 2009
    Posts
    359

    Re: PHP script for memory usage

    Check out this code
    Code:
    class nd {
        public $prtnd;
        public $chnd = array();
        function nd() {
            $this->nodeValue = st_rep('0123456789', 128);
        }
    }
    function createRelationship() {
        $prt = new nd();
        $chd = new nd();
        $prt->chnd[] = $chd;
        $chd->prtnd = $prt;

Similar Threads

  1. Low memory usage in nokia n9
    By Dhulipala in forum Portable Devices
    Replies: 3
    Last Post: 18-01-2012, 10:17 AM
  2. Memory Usage of iexplore.exe
    By mellisahi in forum Motherboard Processor & RAM
    Replies: 3
    Last Post: 14-08-2009, 11:34 PM
  3. SQLServr.exe Memory Usage
    By Matrix316 in forum Operating Systems
    Replies: 3
    Last Post: 06-07-2009, 01:12 PM
  4. svchost.exe - 100% CPU usage, and 100 MB memory usage.
    By bildos in forum Windows Server Help
    Replies: 3
    Last Post: 01-02-2007, 03:39 AM
  5. SBSMonitoring/SQL Memory allocation error (run away Memory usage)
    By Dilbert in forum Small Business Server
    Replies: 1
    Last Post: 21-09-2005, 11:32 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,035,457.21291 seconds with 17 queries