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.

Does /tmp clear itself out?

Discussion in 'General Discussion' started by dory36, Apr 18, 2006.

  1. dory36

    dory36 Well-Known Member

    Joined:
    Aug 30, 2003
    Messages:
    179
    Likes Received:
    0
    Trophy Points:
    16
    A user's php script creates a 10k file in /tmp using tempnam(). His script fails if he issues the unlink command at the end of his script, as the process using the temp file seems to still be executing when the unlink command is executed.

    My question . . . do I need to clean these files out periodically, or is /tmp purges automatically?
     
  2. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    Well, in the first instance, that's a programming problem that should be easily fixed by unlocking the resource before trying to delete it. You could also insist the user create temporary files within their account instead.

    /tmp should be cleared down if you have tmpwatch enabled, usually via cron in:

    /etc/cron.daily/tmpwatch

    However, that only clears down to 720 hours, which is a long time so you might want to reduce that down to say, 48 if you want /tmp kept more tidy.
     
  3. dory36

    dory36 Well-Known Member

    Joined:
    Aug 30, 2003
    Messages:
    179
    Likes Received:
    0
    Trophy Points:
    16
    Thanks much. I'll work on the user.

    In the meantime, is there any problem with deleting files in /tmp owned by "nobody" that are over 24 hours old?
     
  4. chirpy

    chirpy Well-Known Member

    Joined:
    Jun 15, 2002
    Messages:
    13,475
    Likes Received:
    20
    Trophy Points:
    38
    Location:
    Go on, have a guess
    Not usually, no. It would be odd for an web application to need a temporary file for that long.
     
  5. dory36

    dory36 Well-Known Member

    Joined:
    Aug 30, 2003
    Messages:
    179
    Likes Received:
    0
    Trophy Points:
    16
    Thanks. Looks like I'll have to rely on the php script deleting day-old stuff when it runs.

    Surprisingly (to me at least) the tempnam() function works slightly differently than "advertised" on a Linux server. The php documentation says the function tempnam(dir,prefix) will create a temp file in dir -- but in Linux, it will only create it in /tmp, and anything in the function call to the contrary is ignored.
     
Loading...

Share This Page