Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8559587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:05:16+00:00 2026-06-11T16:05:16+00:00

Using PHP, I’d like to get the total memory available to the system (not

  • 0

Using PHP, I’d like to get the total memory available to the system (not just the free or used memory).

On Linux it’s quite straight forward. You can do:

$memory = fopen('/proc/meminfo');

and then parse the file.

Is anyone aware of an equivalent method for Windows? I’m open to any suggestions.

Edit: We have a solution (but StackOverflow won’t let me answer my own question):

exec( 'systeminfo', $output );

foreach ( $output as $value ) {
    if ( preg_match( '|Total Physical Memory\:([^$]+)|', $value, $m ) ) {
        $memory = trim( $m[1] );
}

Not the most elegant solution, and it’s very slow, but it suits my need.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:05:17+00:00Added an answer on June 11, 2026 at 4:05 pm

    You can do this via exec:

    exec('wmic memorychip get capacity', $totalMemory);
    print_r($totalMemory);
    

    This will print (on my machine having 2×2 and 2×4 bricks of RAM):

    Array
    (
        [0] => Capacity
        [1] => 4294967296
        [2] => 2147483648
        [3] => 4294967296
        [4] => 2147483648
        [5] =>
    )
    

    You can easily sum this by using

    echo array_sum($totalMemory);
    

    which will then give 12884901888. To turn this into Kilo-, Mega- or Gigabytes, divide by 1024 each, e.g.

    echo array_sum($totalMemory) / 1024 / 1024 / 1024; // GB
    

    Additional command line ways of querying total RAM can be found in

    • https://superuser.com/questions/315195/is-there-a-command-to-find-out-the-available-memory-in-windows

    Another programmatic way would be through COM:

    // connect to WMI
    $wmi = new COM('WinMgmts:root/cimv2');
    
    // Query this Computer for Total Physical RAM
    $res = $wmi->ExecQuery('Select TotalPhysicalMemory from Win32_ComputerSystem');
    
    // Fetch the first item from the results
    $system = $res->ItemIndex(0);
    
    // print the Total Physical RAM
    printf(
        'Physical Memory: %d MB', 
        $system->TotalPhysicalMemory / 1024 /1024
    );
    

    For details on this COM example, please see:

    • http://php.net/manual/en/book.com.php
    • MSDN: Constructing a Moniker String
    • MSDN: Win32_ComputerSystem class

    You can likely get this information from other Windows APIs, like the .NET API., as well.


    There is also PECL extension to do this on Windows:

    • win32_ps_stat_mem — Retrieves statistics about the global memory utilization.

    According to the documentation, it should return an array which contains (among others) a key named total_phys which corresponds to “The amount of total physical memory.“

    But since it’s a PECL extension, you’d first have to install it on your machine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using PHP on Linux, I'd like to determine whether a shell command run using
Using PHP on Linux, I can just use the is_link() function to detect whether
Using PHP I echo out table rows in a loop like this: <?php /*
Using PHP I would like to be able to list root's crontab. I am
Using php I am trying to get some data from a .csv file which
Using PHP I'd like to compare an actual ip address to part of one,
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Using PHP , I would like to make a while loop that reads a
Using PHP's ReflectionClass. Is this possible? I want to get a list of methods
Using PHP and MySQL I'm trying to get all the distinct values out the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.