The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

User's disk free space in PHP

Discussion in 'cPanel Developers' started by Denitz, Mar 9, 2007.

  1. Denitz

    Denitz Registered

    Joined:
    Mar 9, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    I need a PHP function to determine the user's free space available (and the disk space available for the user).
    May be somebody had already developed such a script?
     
  2. twdinc2

    twdinc2 Registered

    Joined:
    Jun 12, 2002
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Pretty certain it uses normal quotas so the command "quota -u USERNAME" should return the results you want...whether this can be executed successfully from PHP I never tried. I imagine any script running as root could access this information, any scripts running as a user (or nobody) probably cannot.

    Regards,
    Kevin
     
  3. webignition

    webignition Well-Known Member

    Joined:
    Jan 22, 2005
    Messages:
    1,880
    Likes Received:
    0
    Trophy Points:
    36
    It pretty much works as Kevin describes - quota -u username will get you all the raw details you need: quota, limit and blocks used.

    Bear in mind that if a user does not have a quota you will not get the details of how many blocks they have used. In such cases, running du -sp /home/username will get you details of how much space their home dir takes which is better than nothing.

    Since a user's home dir may not be in /home, use the du command with care - the above is merely an example. My method for checking how much space a user's home dir takes up first parses out the user's home dir from /etc/passwd.

    If you can write a PHP wrapper for the above commands and parse out the necessary details you're half way there.

    As to executing the script, the safest way I've found is to pop such scripts where 3rd party WHM scripts live and call them from your frontend via the whmreq() function as part of the remote access features, or just write a simple curl wrapper - I use both methods for various reasons.

    I've written a long tutorial on how to do this in general and so won't reiterate the details here - take a look at http://forums.cpanel.net/showthread.php?t=46362 for those details.
     
Loading...
Similar Threads - User's disk free
  1. Scruff
    Replies:
    4
    Views:
    392

Share This Page