1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

"Warning: Unknown(): Failed to write session data (files)"

Discussion in 'General Discussion' started by majoosh, Mar 14, 2008.

  1. majoosh

    majoosh Member

    Joined:
    Feb 18, 2006
    Messages:
    93
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    India
    Hi guys,

    Am getting the following error in our server:

    ========================================
    Warning: session_register(): open(/tmp/sess_65cd921b8ba993f3c437e02daa315e68, O_RDWR) failed: No such file or directory (2) in /home/bla/public_html/admin/index.php on line 1

    Warning: session_register(): Cannot send session cookie - headers already sent by (output started at /home/bla/public_html/admin/index.php:1) in /home/bla/public_html/admin/index.php on line 1

    Warning: session_register(): Cannot send session cache limiter - headers already sent (output started at /home/bla/public_html/admin/index.php:1) in /home/bla/public_html/admin/index.php on line 1
    Warning: Unknown(): open(/tmp/sess_65cd921b8ba993f3c437e02daa315e68, O_RDWR) failed: No such file or directory (2) in Unknown on line 0

    Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0
    =====================================


    Also I have seen so many thread opened in forum regarding the same issue without any resolution :(


    It's not any problem with /tmp permission. Here are the permission and df -h results for my server
    ===========
    root [/tmp]# df -h
    /usr/tmpDSK 484M 14M 445M 3% /tmp
    /tmp 484M 14M 445M 3% /var/tmp
    =========
    ==========
    root[/tmp]# mount
    /dev/hda3 on / type ext3 (rw)
    none on /proc type proc (rw)
    usbdevfs on /proc/bus/usb type usbdevfs (rw)
    /dev/hda1 on /boot type ext3 (rw)
    none on /dev/pts type devpts (rw,gid=5,mode=620)
    /dev/hde2 on /home type ext3 (rw,usrquota)
    none on /dev/shm type tmpfs (rw,noexec,nosuid)
    /usr/tmpDSK on /tmp type ext3 (rw,noexec,nosuid,loop=/dev/loop0)
    /tmp on /var/tmp type none (rw,noexec,nosuid,bind)
    =============

    ============
    root[/tmp]# php -v
    PHP 4.4.2 (cgi) (built: Jun 10 2006 04:53:36)
    Copyright (c) 1997-2006 The PHP Group
    Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies
    with Zend Extension Manager v1.0.6, Copyright (c) 2003-2004, by Zend Technologies
    ============

    I have checked all possibilities :( mount, /tmp permission , php.ini ....but no clue :(

    session.save_path is /tmp in php.ini

    Am using old version of easyapache...and not using phpsuexec

    I have tried wiping the session files and the issue is fixed temperaroly but everytime I have to do this when customer reports this :( and that's going to be a real pain :confused:

    As per instruction from a cpanel guy I have set "session.bug_compat_42 = Off" (without the quotes) in php.ini file and restart apache and didn't do any trick :(

    This started recently ..... Any idea if cpanel did any updates recently ???


    Thanks
    Mojo
     
  2. mctDarren

    mctDarren Member

    Joined:
    Jan 6, 2004
    Messages:
    668
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    New Jersey
    Mojo, is your /tmp directory simply getting overrun with SESS files? If so, try this:

    make a file in scripts called cleantmp, put the following in it:
    Code:
    # This script cleans out /tmp of empty, root, cpanel
    # and nobody session files in /tmp
    # rev 2.0b by Darren - 8.19.07
    
    # if --test is passed, we just show the results
    if [ "$1" == "--test" ]
    then
            CMD="-exec ls -la"
            echo "$0: test mode"
    else
            CMD="-exec rm -rf"
    fi
    
    if [ "$1" == "--help" ]
    then
            echo ""
            echo "cleantmp will clean out your tmp directory for you"
            echo ""
            echo "Parameters:"
            echo "--test            to run in test mode"
            echo "--help            display this file"
            echo "-a accountname    to remove all files owned by account name"
            echo "-e                cleans out all empty (zero length) files"
            echo ""
            exit 0
    fi
    
    if [ "$1" == "-a" ]
    then
            echo ""
            echo "Removing session file for account $2"
            find /tmp -name "sess*" -user $2 -maxdepth 1 $CMD {} \;
            echo "completed"
            echo ""
            exit 0
    fi
    
    if [ "$1" == "-e" ]
    then
            echo ""
            echo "Cleaning out empty files from /tmp"
            find /tmp -name "sess*" -empty -maxdepth 1 $CMD {}  \;
            echo "completed"
            echo ""
            exit 0
    fi
    
    
    # remove empty session files that are over 2 hours old
    find /tmp -name "sess*" -empty -mmin +120 -maxdepth 1 $CMD {}  \;
    
    # remove root owned session files
    find /tmp -name "sess*" -user root -maxdepth 1 $CMD {} \;
    
    # remove nobody session files
    find /tmp -name "*sess*" -user nobody -maxdepth 1 $CMD {} \;
    
    # remove cpanel owned session files
    find /tmp -name "sess*" -user cpanel -maxdepth 1 $CMD {} \;
    
    # remove any session file over 5 hours old
    find /tmp -name "sess*" -mmin +300 -maxdepth 1 $CMD {} \;
    
    # remove any spamassassin file over 4 hours old
    find /tmp -name ".spamassassin*" -mmin +240 -maxdepth 1 $CMD {} \;
    
    Now save, and chmod it so it can be run (use your discretion for perm level):
    chmod 755 /scripts/cleantmp

    Run it as /scripts/cleantmp --test to view which files will be removed or /scripts/cleantmp -a accountname to remove all files owned by account name. And running it with "-e" will remove all empty session files.

    What we do on most boxes is have it run in cron.hourly so that it purges session files. It cleans empties that are over 2 hours old, and normal ones that are over 5 hours old. Keep in mind, this may break software that uses "Keep Me Logged In Indefinitely" option for users. But the script could be easily modified to skip some session files if needed.

    So, go to /etc/cron.hourly and create a file called cleantmp. Put this into it:
    Code:
    #!/bin/bash
    
    /scripts/cleantmp -e >/dev/null 2>&1
    /scripts/cleantmp >/dev/null 2>&1
    
    and save it, then do the same permissions procedure as above. Now every hour, the script wil clean out empty and older SESS files and keep your sites up. Modify this and the other script as needed.

    Hope this helps!
     
  3. majoosh

    majoosh Member

    Joined:
    Feb 18, 2006
    Messages:
    93
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    India
    Hi serversphere,

    You RoCk!!!! ;) but a server reboot fixed the problem :D


    Thanks
    Mojo
     
  4. majoosh

    majoosh Member

    Joined:
    Feb 18, 2006
    Messages:
    93
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    India
    The error poped up again :(. server reboot is not good solution ...


    What's causing this error ? any idea ?


    Mojo
     
  5. majoosh

    majoosh Member

    Joined:
    Feb 18, 2006
    Messages:
    93
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    India
    session.gc_maxlifetime=1440 that will do the trick ;)

    Thanks
    Mojo
     
  6. majoosh

    majoosh Member

    Joined:
    Feb 18, 2006
    Messages:
    93
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    India
    Still having problem ... and I see the error kernel: EXT3-fs error (device loop(7,0)): ext3_readdir: bad entry in directory in /var/log/messeges


    Any idea ?

    Majoosh
     
  7. nerbonne

    nerbonne Member

    Joined:
    Aug 19, 2007
    Messages:
    53
    Likes Received:
    0
    Trophy Points:
    6
    Are you using temporary urls to access the sites? The only time I have session problems is when I use the temp urls. The first site is ok, but the second site I try to go to on the same server causes a problem. This will only occur on a CGI server. The reason is that your session is owned by user one, so user two can't write to it.

    Understand?
     
  8. majoosh

    majoosh Member

    Joined:
    Feb 18, 2006
    Messages:
    93
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    India
    But why the error error kernel: EXT3-fs error (device loop(7,0)): ext3_readdir: bad entry in directory ?



    Majoosh
     
  9. majoosh

    majoosh Member

    Joined:
    Feb 18, 2006
    Messages:
    93
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    India
    I rebuild /tmp and that fixed all the problem ;)


    Majoosh
     
  10. donneo2000

    donneo2000 New Member

    Joined:
    May 23, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Mojo.. thanx for posting the solution :)
     
  11. donneo2000

    donneo2000 New Member

    Joined:
    May 23, 2009
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    rebuilding /tmp will not fix the issue always. You may need to do the following as a permanent fix:

    touch /var/cpanel/usecpphp
     
  12. postcd

    postcd Member

    Joined:
    Oct 22, 2010
    Messages:
    441
    Likes Received:
    0
    Trophy Points:
    16
    Yes, removing all session files fixed my problem, i think cause was that i have switched PHP Handler (SuPHP and CGI). then i entered /tmp (cd /tmp), then i removed session files of wordpress (mkdir z ; mv sess_* z)
    Solved and im very happy.
     
  13. Secmas

    Secmas Member

    Joined:
    Feb 18, 2005
    Messages:
    310
    Likes Received:
    0
    Trophy Points:
    16
     
  14. mctDarren

    mctDarren Member

    Joined:
    Jan 6, 2004
    Messages:
    668
    Likes Received:
    2
    Trophy Points:
    18
    Location:
    New Jersey
    It was mainly written as a quick lesson for techs about writing a quick BASH script to perform a task, and evolved into a quick way to clean out session files from tmp that techs liked. It would be easy to expand it to do what you want, however. Use it as a base and expand it however you would like.
     
  15. Secmas

    Secmas Member

    Joined:
    Feb 18, 2005
    Messages:
    310
    Likes Received:
    0
    Trophy Points:
    16
    Thanks ServerSphere.

    I can modify the BASH file, that is the easy part, lol. What I really don't know if it is ok to delete any NOBODY file with more than a week old, may be you can help me on that or if it is ok to delete any file older than 15 days ago.

    Regards,

    Sergio
     
  16. crazyaboutlinux

    Joined:
    Nov 3, 2007
    Messages:
    930
    Likes Received:
    0
    Trophy Points:
    16
    steps required to rebuild /tmp

    thanks in advance
     
  17. siveict.co.za

    siveict.co.za New Member

    Joined:
    Oct 4, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Go to your PHP.ini file or find PHP.ini EZConfig on your Cpanel and set your session.save_path to the full path leading to the tmp file, i.e: /home/cpanelusername/tmp
     
  18. pwhjenny

    pwhjenny Member

    Joined:
    Aug 31, 2012
    Messages:
    135
    Likes Received:
    0
    Trophy Points:
    16
    We had similar problem as one of our client was filling up /tmp file. We had created /tmp partition in the customers home directory and defined session files to be stored there so his files would not fill up primary tmp directory.
     
  19. giovanni-m

    giovanni-m New Member

    Joined:
    Jan 19, 2014
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    For me it was enough to check if the session exists. If not, delete the session cookie.

    if(empty($_SESSION)) {
    if (isset($_COOKIE[session_name()])) {
    setcookie(session_name(), '', time()-42000, '/');
    }
    }
    session_start();
     
  20. giovanni-m

    giovanni-m New Member

    Joined:
    Jan 19, 2014
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    1
    Or better... checking if the file of session also exists, before delete the cookie:

    PHP:
    session_save_path("/tmp");
    if(empty(
    $_SESSION)) {
        if (isset(
    $_COOKIE[session_name()])) {
            if(!
    file_exists("/tmp/sess_".$_COOKIE[session_name()])) {
                
    setcookie(session_name(), ''time()-42000'/');
            }
        }
    }
    session_start();
     

Share This Page