PHP Session garbage collection

Discussion in 'General' started by honse33, Mar 5, 2019.

  1. honse33

    honse33 New Member

    Hey guys,

    I'm wondering about how ISPConfig deals with the PHP Sessions on a debian system. It seems, that the normal cron by php (/etc/cron.d/php) executes, but won't flush the ones of the hosting sites. On a pretty old forum thread (2010-ish) I read that the cron.daily.php should handle the task. Unfortunately this file has been merged to cron.php as well as the classes in "server/lib/classes/cron.d" - but none of them seem to handle anything in relation to the php sessions in $client/tmp/. Problably I overread it in my quick lookup.

    Can someone enlighten me on this?
     
  2. till

    till Super Moderator Staff Member ISPConfig Developer

    The PHP session cleanup code is in the file 200-logfiles.inc.php
     
  3. honse33

    honse33 New Member

    Oh, my bad. Thanks for hinting.

    As the records come from the db, would you mind implementing a session timeout input field per site/record? The user may then decide when a php session needs to get garbage collected. Dropdown "by day" (-mtime) or "by minute" (-mmin) with an input field for the number of days/minutes.
     
  4. Pimmal

    Pimmal New Member

    Hello, i have also the problem that the tmp folder gets not cleaned up.
    If i run cron_debug.php --cronjob=200-logfiles.inc.php then i get the following output
    Code:
    sh: line 0: cd: ?: No such file or directory
    sh: line 0: cd: ?: No such file or directory
    sh: line 0: cd: ?: No such file or directory
    sh: line 0: cd: ?: No such file or directory
    sh: line 0: cd: ?: No such file or directory
    sh: line 0: cd: ?: No such file or directory
    sh: line 0: cd: ?: No such file or directory
    finished.
    How can i fix this?
     
  5. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    My guess is the command to be executed is wrong. Maybe $tmp_path is not set?
     
  6. Pimmal

    Pimmal New Member

    Wer i need to set tmp path?
     
  7. Taleman

    Taleman Well-Known Member HowtoForge Supporter

    It was just a guess. I looked at file 200-logfiles.inc.php and there was shell command with cd. That command would fail like
    No such file or directory if $tmp_path is not set.
     
  8. Pimmal

    Pimmal New Member

    i have only tested with that command because i have found it in a board thread. My problem is that my tmp folders dont gets cleaned up and gwoing each day 2GB of files.
     
  9. Pimmal

    Pimmal New Member

    nobody can help me here?
     
  10. Chris_UK

    Chris_UK Member HowtoForge Supporter

    Code:
    var=$(locate 200-logfiles.inc.php) && nano $var;
    This will open the file, presuming you have no copy of it, you will need to be root to access that file.

    However, the code block you want to look at is:
    Code:
                    $sql = "SELECT domain_id, domain, document_root, system_user FROM web_domain WHERE server_id = ?";
                    $records = $app->db->queryAllRecords($sql, $conf['server_id']);
                    $app->uses('system');
                    if(is_array($records)) {
                            foreach($records as $rec){
                                    $tmp_path = realpath($rec['document_root'].'/tmp');
                                    if($tmp_path != '' && strlen($tmp_path) > 10 && is_dir($tmp_path) && $app->system->is_user($rec['system_user'])){
                                            exec("cd ?; find . -mtime +1 -name 'sess_*' | grep -v -w .no_delete | xargs rm > /dev/null 2> /dev/null", $tmp_path);
                                    }
                            }
                    }
    
    Looking at this, you first want to check that document_root is set under web_domain table for any affected website. Also, I recall reading a thread a day or so ago about the server_id not being set somewhere which might be the problem, although i suspect not if the logs are clearing properly.

    If none of these are the issue then I am not sure what would cause this for you, in one of my php websites:
    du -h /var/www/clients/client2/web1 outputs a total disk usage of 207M for an entire php website with its tmp directory being ~ 31M.

    It seems for me that clean up is taking place for the website under the latest version of ISPConfig and Ubuntu 18.04 and running on php7.2 FPM. I am not sure these details matter but I am trying to provide as much information as possible about a system that appears to be working as expected.
     

Share This Page