get server ram with php

后端 未结 9 1643
抹茶落季
抹茶落季 2020-12-05 00:19

Is there a way to know the avaliable ram in a server (linux distro) with php (widthout using linux commands)?

edit: sorry, the objective is to be aware of the ram av

9条回答
  •  无人及你
    2020-12-05 00:51

    Small and tidy function to get all of its values associated to their keys.

    $contents = file_get_contents('/proc/meminfo');
    preg_match_all('/(\w+):\s+(\d+)\s/', $contents, $matches);
    $info = array_combine($matches[1], $matches[2]);
    
    // $info['MemTotal'] = "2047442"
    

提交回复
热议问题