2

Whats the maximum number of files that php can handle in the "session.save_path" directory, when "session.save_handler = files" is used?

Actually we had problems, when the number of files reaches a high level. I cannot tell you the number we had, because I cleaned out te folder.

Users tried to log in, but where kicked out right after their first klick within the application.

Andi
  • 551
  • 4
  • 7
  • PHP doesn't impose any limit on the number of session files, but filesystems do have limits after which performance begins to take an adverse hit – Mark Baker Jan 30 '14 at 09:04

1 Answers1

2

As far as I know, there's no specific hard-limit on the PHP side. However, most file systems perform badly when they have huge directory entries.

You possibly want to split your session files in subdirectories, as the manual explains:

session.save_path string

session.save_path defines the argument which is passed to the save handler. If you choose the default files handler, this is the path where the files are created. See also session_save_path().

There is an optional N argument to this directive that determines the number of directory levels your session files will be spread around in. For example, setting to '5;/tmp' may end up creating a session file and location like /tmp/4/b/1/e/3/sess_4b1e384ad74619bd212e236e52a5a174If.

Beware that you first need to create the directory tree yourself. It shouldn't be difficult to write a PHP script to do so.

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • Thanks for your hint! Assuming you're right, it maybe that the ext4 file system had a problem handling the number of files within the directory. – Andi Jan 30 '14 at 09:34
  • BTW, next time it happens I suggest you verify the modification date of session files. I once found a crowded session directory due to a misconfigured system that was simply not removing old data. I had session files that hadn't been touched in months. – Álvaro González Jan 30 '14 at 09:47
  • Hi, you are right, this is what happend. I fixed it by adjusting session.gc_probability, session.gc_divisor, session.gc_maxlifetime. See: http://stackoverflow.com/questions/654310/cleanup-php-session-files – Andi Jan 30 '14 at 10:38