清理PHP会话文件 [英] cleanup php session files

查看:85
本文介绍了清理PHP会话文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网站上,我使用PHP会话.会话信息存储在我的./session路径中的文件中.几个月后,我发现这些会话文件从未删除,到目前为止,此目录中有145.000个文件.

On my website I use PHP sessions. Session information is stored in files in my ./session path. After a few months I discovered that these session files are never deleted, by now there are 145.000 of them in this directory.

这些应该如何清理?我是否需要以编程方式执行此操作,还是可以在可以自动进行此清除操作的地方使用该设置?

How should these be cleaned up? Do I have to do it programmatically, or is ther a setting I can use somewhere that would have this cleanup happen automatically?

EDIT (忘了提及):该站点在提供商处运行,所以我无权访问命令行.我确实有ftp访问权限,但是会话文件属于另一个用户(我想应该是网络服务器运行的那个用户)从我得到的第一个答案中,我认为这不仅是服务器或PHP上的设置,所以我想我会必须在PHP中为其实现一些功能,并定期从浏览器中调用它(也许是从我在家中自己的计算机上运行的cron作业)

EDIT forgot to mention: This site runs at a provider, so I don't have access to a command line. I do have ftp-access, but the session files belong to another user (the one the webserver proces runs I guess) From the first answers I got I think it's not just a setting on the server or PHP, so I guess I'll have to implement something for it in PHP, and call that periodically from a browser (maybe from a cron job running on my own machine at home)

推荐答案

要正确处理会话,请查看 http://php.net/manual/en/session.configuration.php .

To handle session properly, take a look at http://php.net/manual/en/session.configuration.php.

您将在其中找到以下变量:

There you'll find these variables:

  • session.gc_probability
  • session.gc_divisor
  • session.gc_maxlifetime

这些控制每个页面请求运行的垃圾收集器(GC)的可能性.

These control the garbage collector (GC) probability of running with each page request.

您可以在开始时使用 ini_set()进行设置.您的脚本或.htaccess文件,这样您就可以在一定程度上确定它们会在某个时间被删除.

You could set those with ini_set() at the beginning of your script or .htaccess file so you get certainty to some extent they will get deleted sometime.

这篇关于清理PHP会话文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆