Page 1 of 2 12 LastLast
Results 1 to 15 of 20

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

  1. #1
    Registered Member majoosh's Avatar
    Join Date
    Feb 2006
    Location
    India
    Posts
    93

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

    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

    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. #2
    Registered Member mctDarren's Avatar
    Join Date
    Jan 2004
    Location
    New Jersey
    Posts
    666
    cPanel/WHM Access Level

    Root Administrator

    Default

    Quote Originally Posted by majoosh View Post
    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
    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. #3
    Registered Member majoosh's Avatar
    Join Date
    Feb 2006
    Location
    India
    Posts
    93

    Default

    Hi serversphere,

    You RoCk!!!! but a server reboot fixed the problem


    Thanks
    Mojo

  4. #4
    Registered Member majoosh's Avatar
    Join Date
    Feb 2006
    Location
    India
    Posts
    93

    Default

    The error poped up again . server reboot is not good solution ...


    What's causing this error ? any idea ?


    Mojo

  5. #5
    Registered Member majoosh's Avatar
    Join Date
    Feb 2006
    Location
    India
    Posts
    93

    Default

    session.gc_maxlifetime=1440 that will do the trick

    Thanks
    Mojo

  6. #6
    Registered Member majoosh's Avatar
    Join Date
    Feb 2006
    Location
    India
    Posts
    93

    Default

    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. #7
    Registered Member
    Join Date
    Aug 2007
    Posts
    53

    Default

    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. #8
    Registered Member majoosh's Avatar
    Join Date
    Feb 2006
    Location
    India
    Posts
    93

    Default

    But why the error error kernel: EXT3-fs error (device loop(7,0)): ext3_readdir: bad entry in directory ?



    Majoosh

  9. #9
    Registered Member majoosh's Avatar
    Join Date
    Feb 2006
    Location
    India
    Posts
    93

    Default

    I rebuild /tmp and that fixed all the problem


    Majoosh

  10. #10
    Registered Member
    Join Date
    May 2009
    Posts
    5

    Default

    Mojo.. thanx for posting the solution

  11. #11
    Registered Member
    Join Date
    May 2009
    Posts
    5

    Default

    rebuilding /tmp will not fix the issue always. You may need to do the following as a permanent fix:

    touch /var/cpanel/usecpphp

  12. #12
    Registered Member postcd's Avatar
    Join Date
    Oct 2010
    Posts
    324

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

    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. #13
    Registered Member
    Join Date
    Feb 2005
    Posts
    311

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

    [QUOTE=serversphere;356682]

    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 {} \;
    Hello Darren,
    I know this post is very old but I want to know if you have an update of your script, thanks.

    By the way, why your script doesn't clean files that are no "sess" but that are very old and most of the time are files that started with the YearMonthDate like as an example "20110629" written by nobody user?

    Sergio

  14. #14
    Registered Member mctDarren's Avatar
    Join Date
    Jan 2004
    Location
    New Jersey
    Posts
    666
    cPanel/WHM Access Level

    Root Administrator

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

    Quote Originally Posted by Secmas View Post
    why your script doesn't clean files that are no "sess" but that are very old and most of the time are files that started with the YearMonthDate like as an example "20110629" written by nobody user?
    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. #15
    Registered Member
    Join Date
    Feb 2005
    Posts
    311

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

    Quote Originally Posted by serversphere View Post
    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.
    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

Page 1 of 2 12 LastLast

Similar Threads

  1. "Detected session with all messages failed" What does it mean?
    By albatroz in forum E-mail Discussions
    Replies: 3
    Last Post: 07-02-2013, 01:35 PM
  2. Replies: 5
    Last Post: 02-24-2012, 12:35 PM
  3. Replies: 4
    Last Post: 10-02-2007, 03:47 PM
  4. Replies: 17
    Last Post: 04-14-2005, 03:49 AM
bargain