基于 Debian 的系统 Session 在特殊 cron 中的 30 分钟被终止,如何覆盖?

发布于 2024-09-25 20:47:18 字数 1778 浏览 4 评论 0原文

我一直在揪着我的头发试图找出为什么我的会话在 30 分钟后被终止/终止/破坏。看起来基于 Debian 的系统有一个特殊的 cron 运行,它会忽略所有 php.ini 和 apache 配置,并在 30 分钟后终止任何空闲会话。

cron 路径:/etc/cron.d/php5

cron 内部:

# /etc/cron.d/php5: crontab fragment for php5
#  This purges session files older than X, where X is defined in seconds
#  as the largest value of session.gc_maxlifetime from all your php.ini
#  files, or 24 minutes if not defined.  See /usr/lib/php5/maxlifetime

# Look for and purge old sessions every 30 minutes
09,39 *     * * *     root   [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 | xargs -n 200 -r -0 rm

我不擅长配置和设置主机,但我不是系统管理员。有人可以帮我覆盖/编辑/更改/重新配置它,以便我可以设置更长的值吗?我认为 3 小时会很好,但我想了解这些更改,因此如果高层想要缩短/延长会话时间,我会记录如何配置更改。

感谢对此

编辑的任何见解帮助: 添加 /usr/lib/php5/maxlifetime 代码

#!/bin/sh -e

max=1440

for ini in /etc/php5/*/php.ini; do
        cur=$(sed -n -e 's/^[[:space:]]*session.gc_maxlifetime[[:space:]]*=[[:space:]]*\([0-9]\+\).*$/\1/p' $ini 2>/dev/null || true);
        [ -z "$cur" ] && cur=0
        [ "$cur" -gt "$max" ] && max=$cur
done

echo $(($max/60))

exit 0

,以便它看起来正在搜索所有 php.ini 文件,找到最大值,并将其与 1440(即 24 分钟)进行比较。

以下是 php.ini 文件

/etc/php5/apache2/php.ini
session.gc_maxlifetime = 1440 

/etc/php5/cgi/php.ini
session.gc_maxlifetime = 1440

/etc/php5/cli/php.ini
session.gc_maxlifetime = 1440

,但为什么我的脚本会话在 30 分钟而不是 24 分钟时被终止?

编辑#2: CRON 每 30 分钟运行一次,这就是会话看起来每隔 30 分钟被终止的原因。 但也可能是 24 到 54 分钟,仅供参考,

还查看了以下代码:/usr/lib/php5/maxlifetime 它采用了最高值,在我的测试过程中,我试图将阈值降低到加快病情。

看起来我只需要在 php.ini 文件上增加一个即可超过一小时的测试。

Have been pulling out my hair trying to find out why my sessions are being terminated/killed/destroyed at 30 minutes. Well it looks like Debian based systems have a special cron running that ignores all php.ini and apache configurations and kills any idle session at 30 minutes.

The cron path: /etc/cron.d/php5

Inside the cron:

# /etc/cron.d/php5: crontab fragment for php5
#  This purges session files older than X, where X is defined in seconds
#  as the largest value of session.gc_maxlifetime from all your php.ini
#  files, or 24 minutes if not defined.  See /usr/lib/php5/maxlifetime

# Look for and purge old sessions every 30 minutes
09,39 *     * * *     root   [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 | xargs -n 200 -r -0 rm

I'm not bad at configuring and setting up hosts but I'm no sysAdmin. Could someone please help me override/edit/change/reconfigure this so I can set the value longer? I think 3 hours would be nice but I would like to understand the changes so if someone higher up wants to make the session time shorter/longer I con document how to configure the change.

Thanks to any insight help on this

EDIT:
Adding /usr/lib/php5/maxlifetime code

#!/bin/sh -e

max=1440

for ini in /etc/php5/*/php.ini; do
        cur=$(sed -n -e 's/^[[:space:]]*session.gc_maxlifetime[[:space:]]*=[[:space:]]*\([0-9]\+\).*$/\1/p' $ini 2>/dev/null || true);
        [ -z "$cur" ] && cur=0
        [ "$cur" -gt "$max" ] && max=$cur
done

echo $(($max/60))

exit 0

so it looks to be searching all the php.ini files, finds the greatest value, compares it to 1440 (which is 24 minutes).

Here are the php.ini files

/etc/php5/apache2/php.ini
session.gc_maxlifetime = 1440 

/etc/php5/cgi/php.ini
session.gc_maxlifetime = 1440

/etc/php5/cli/php.ini
session.gc_maxlifetime = 1440

but why does my script session get killed at 30 minutes and not 24 minutes?

EDIT #2:
CRON running every 30 minutes is why the session looks to be killed at 30 minute intervals.
But it could also be 24 to 54 minutes, FYI

Also looking over the code in: /usr/lib/php5/maxlifetime it's taking the highest value and during my testing I was trying to lower the threshold to speed up the condition.

Looks like I just need to increase one on the php.ini files to over one hour test test.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

爱给你人给你 2024-10-02 20:47:18

编辑文件 /usr/lib/php5/maxlifetime

该值应以秒为单位。该文件实际上还会检查您的 php.ini 所以我不知道为什么它不适合您。

Edit the file /usr/lib/php5/maxlifetime

The value should be in seconds. This file will actually also check your php.ini so I don't know why it wasn't working for you.

万劫不复 2024-10-02 20:47:18

这是 serverfault.com 的问题。

但是,请更改 /etc/php5/apache2/php.ini 中的 session.gc_maxlifetime ,或者 - 如果您没有 apache2 - 另一个 之一/etc/php5/*/php.ini 文件。然后,脚本 /usr/lib/php5/maxlifetime 将使用在任何这些文件中找到的该设置的最大值。

编辑 maxlifetime 不会有任何帮助,或者至少只有在 php5-common 包再次更新之前才会有帮助。

This is a question for serverfault.com.

However, change session.gc_maxlifetime in /etc/php5/apache2/php.ini or - if you don't have an apache2 one - one of the other /etc/php5/*/php.ini files. The script /usr/lib/php5/maxlifetime will then use the maximum for that setting found in any of those files.

Editing maxlifetime won't help or at least only until the php5-common package is updated again.

人│生佛魔见 2024-10-02 20:47:18

您可以提供自己的会话路径 session .save_path 完全使用不同的处理程序session.save_handler

但是,您需要提供适当的机制来管理不需要的会话文件。

在我的 php.ini 中发现了这个问题,

; NOTE: If you are using the subdirectory option for storing session files
;       (see session.save_path above), then garbage collection does *not*
;       happen automatically.  You will need to do your own garbage
;       collection through a shell script, cron entry, or some other method.
;       For example, the following script would is the equivalent of
;       setting session.gc_maxlifetime to 1440 (1440 seconds = 24 minutes):
;          cd /path/to/sessions; find -cmin +24 | xargs rm

我最近遇到了这个问题,因为我使用 PHP 和 mod_fcgid 以及自定义 session.save_path< /code> 对于每个虚拟主机。

You can provide your own session path session.save_path OR use a different handler altogether session.save_handler

You'll however need to provide appropriate mechanism for managing unwanted session files.

Found this in my php.ini

; NOTE: If you are using the subdirectory option for storing session files
;       (see session.save_path above), then garbage collection does *not*
;       happen automatically.  You will need to do your own garbage
;       collection through a shell script, cron entry, or some other method.
;       For example, the following script would is the equivalent of
;       setting session.gc_maxlifetime to 1440 (1440 seconds = 24 minutes):
;          cd /path/to/sessions; find -cmin +24 | xargs rm

I recently ran into this problem where unwanted session files were accumulating because I was using PHP and mod_fcgid with a custom session.save_path for each virtualhost.

那支青花 2024-10-02 20:47:18

如果您来到这里是因为您的 cron 每 30 分钟(在 09 和 39)抛出错误,您的系统日志和/或邮箱中可能会出现类似的错误:

[ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 | xargs -n 200 -r -0 rm
PHP Fatal error: Directive 'allow_call_time_pass_reference' is no longer available in PHP in Unknown on line 0

原因可能是您将 Debian 升级到 Wheezy 并且您的 /etc/php5/apache2/php.ini 中有旧条目。

我必须注释掉以下几行,错误就消失了。

  • allow_call_time_pass_reference
  • register_long_arrays

我写这篇文章是因为如果您搜索错误消息,这是最热门的谷歌结果之一,它可能会影响许多维护多个版本的 debian 安装的用户/管理员。

PS:这对我很有帮助: http://vernontbludgeon.com/blog/archives/2013/10/debian-php-session-garbage-collection-maxlifetime-fails-when-php.ini-has -obsolete-directives.html

If you came here because your cron is throwing errors every 30 Minutes (at 09 and 39) you may have simmilar errors in your syslog and/or mailbox:

[ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 | xargs -n 200 -r -0 rm
PHP Fatal error: Directive 'allow_call_time_pass_reference' is no longer available in PHP in Unknown on line 0

The reason for this maybe that you upgraded your Debian to Wheezy and you have old entrys in your /etc/php5/apache2/php.ini.

I had to comment out the following lines and the errors vanished.

  • allow_call_time_pass_reference
  • register_long_arrays

Im writing this because this is one of the top google results if you search for the error-messages and it may affect many users/admins who maintained thier debian-installations for more than one release.

PS: This helped me very much: http://vernontbludgeon.com/blog/archives/2013/10/debian-php-session-garbage-collection-maxlifetime-fails-when-php.ini-has-obsolete-directives.html

神经大条 2024-10-02 20:47:18

它就在你的 php5 cronjob 片段中:

每 30 分钟查找并清除旧会话

如果脚本执行时间不超过每 30 分钟,那么脚本清除 24 分钟的旧会话并不重要:)

It's right there in your php5 cronjob fragment:

Look for and purge old sessions every 30 minutes

It doesn't matter the script purges 24 minute old sessions, if the script isn't executed more than every 30 minutes :)

怎会甘心 2024-10-02 20:47:18

使用下面的 cron 删除未使用的会话。

39 20     * * *     root   [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 | xargs -r -0 rm

Use below cron to delete unused sessions.

39 20     * * *     root   [ -x /usr/lib/php5/maxlifetime ] && [ -d /var/lib/php5 ] && find /var/lib/php5/ -depth -mindepth 1 -maxdepth 1 -type f -cmin +$(/usr/lib/php5/maxlifetime) -print0 | xargs -r -0 rm
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文