Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    New Coder
    Join Date
    Dec 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Print Processor Type and RAM using php

    Hi,

    I want to know whether if there is any php function or any script that prints the system processor type and RAM available. Is it possible to get system information using any built in php functions.

    Thanks in advance
    stranger

  • #2
    Regular Coder
    Join Date
    Jan 2007
    Posts
    213
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I dont think you can do this with PHP functions but you may beable to use the EXEC command to execute a bash file which outputs this information.
    Matthew Bagley
    Paramiliar Design Studios
    Website Design | Website Development | Search Engine Optimisation (SEO)

  • #3
    New Coder
    Join Date
    Dec 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have tried this in my php script by using file_get_contents("/proc/cpuinfo"). But as this file is read protected , it is displaying a error message that it cannot be read. How can i read the contents of this read protected file.

  • #4
    Regular Coder
    Join Date
    Jan 2007
    Posts
    213
    Thanks
    0
    Thanked 0 Times in 0 Posts
    unsure about reading the file but have you tried executing it

    Code:
    shell_exec("cpuinfo");
    that may work
    Matthew Bagley
    Paramiliar Design Studios
    Website Design | Website Development | Search Engine Optimisation (SEO)

  • #5
    New Coder
    Join Date
    Dec 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi

    I did the same using shell_exec(). It is giving the following error:
    Error: Cannot execute using backquotes in SAFE MODE.

    Thanks in Advance
    stranger

  • #6
    New Coder
    Join Date
    Dec 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have done this using system function
    system ( vi '/proc/cpuinfo').

    But to save the entire output into a variable
    $sysstat = print system(vi '/proc/cpuinfo')

    But $sysstat contains only the first line . How can i print the entire information present in cpuinfo.

    Thanks in Advance
    stranger

  • #7
    Regular Coder
    Join Date
    Jan 2007
    Posts
    213
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well i have never come across that error message vefore hand which is very weird.

    The other option that may work is this...
    Code:
    <?php
    $fp = fopen("/proc/cpuinfo", "r");
    while ($data = fread($fp, 1024)){
      $cpuinfo .= $data;
    }
    echo $cpuinfo;
    That may work depending on how php is setup, it will read the cpuinfo in as a file line by line and store it in the cpuinfo variable
    Matthew Bagley
    Paramiliar Design Studios
    Website Design | Website Development | Search Engine Optimisation (SEO)

  • #8
    New Coder
    Join Date
    Dec 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    But the file is read protected, i am not able to read the file in ' r' mode.

    Thanks in Advance
    stranger.

  • #9
    New Coder
    Join Date
    Dec 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The file /proc/cpuinfois under root privileges. It has neither read nor write permission.

    Thanks
    stranger

  • #10
    Regular Coder
    Join Date
    Jan 2007
    Posts
    213
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i see, well I am away from the office at the moment but there are several other executing commands on php that you can try,

    passthru()
    exec()
    shell_exec()
    system()

    and failing that there are some function I myself have never used but they may work
    proc_open()

    that is meant to open a process and allow you to read / write to it but I have never had the need to use it.

    Just being curiouse but why do you need the processor spec?
    Matthew Bagley
    Paramiliar Design Studios
    Website Design | Website Development | Search Engine Optimisation (SEO)

  • #11
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,058
    Thanks
    10
    Thanked 96 Times in 94 Posts
    Its a device ... but still a file in 'everything is a file' Linux style.
    but this should still work even as an unprivileged user ?
    PHP Code:
    <?php
    exec
    ('cat /proc/cpuinfo',$yaks);
    print_r($yaks);
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #12
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    on both my home machine and my shared-hosting account I, as a non-root user, can read /proc/cpuinfo and /proc/meminfo.

    if you couldn't read the file, then your vi example wouldn't work either...surely?
    My thoughts on some things: http://codemeetsmusic.com
    And my scrapbook of cool things: http://gjones.tumblr.com

  • #13
    New Coder
    Join Date
    Dec 2006
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes , in my machine the /proc/cpuinfo are read protected. So I am unable to read it by using any of your suggested methods. Is there any other alternative

    Thanks in Advance
    stranger

  • #14
    Regular Coder
    Join Date
    Jan 2007
    Posts
    213
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Right I have had time to do a few test for you and if you visit you will see some working code showing that my server runs on a dual 3Ghz CPU's

    CPU Information

    The code to show this is as follows

    PHP Code:
    <?php
        exec 
    ("cat /proc/cpuinfo"$details);
        
        
    $processor1 $details[1]."<br />".$details[4]."<br />".$details[6]."<br />".$details[7];
        
    $processor2 $details[47]."<br />".$details[50]."<br />".$details[52]."<br />".$details[53];
        
        echo 
    "Processor 1 <br>$processor1<br /><br />Processor 2 <br />$processor2";
    ?>
    Hope that helps, if for any reason it doesn't work post the URL to the file for me and I may be able to bug test it from the output
    Matthew Bagley
    Paramiliar Design Studios
    Website Design | Website Development | Search Engine Optimisation (SEO)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •