我需要在mod_perl中做一些简单的时区计算。DateTime不是一个选项。我需要做的是通过设置$ ENV {TZ}并使用localtime和POSIX :: mktime轻松完成,但在线程MPM下,我需要确保一次只有一个线程与环境混淆。(我不关心本地时间的其他用途等)
如何使用互斥锁或其他锁定策略来序列化(在非编组意义上)对环境的访问?我看过的文档并不能很好地解释如何为这个用途创建一个互斥锁。也许有些东西,我只是没有了解你如何创建互斥体。
更新:是的,我知道需要使用Env :: C来设置TZ。
发布于 2018-09-20 09:17:24
由于这个问题,mod_perl 2实际上与mod_perl 1不同地处理%ENV哈希。在mod_perl中,1%ENV直接绑定到环境结构,因此更改%ENV会改变环境。在mod_perl 2中,%ENV哈希是从environ填充的,但不会传回更改。
这意味着你不能再使用$ ENV {TZ}来调整时区 - 特别是在线程环境中。该Apache2的:: LOCALTIME模块将使其成为非螺旋的情况下工作(通过使用信封:: C),但在一个线程化的MPM,这将是坏消息中运行时。
关于此问题,mod_perl源(src / modules / perl / modperl_env.c)中有一些注释:
/* * XXX: what we do here might change:
* - make it optional for %ENV to be tied to r->subprocess_env
* - make it possible to modify environ
* - we could allow modification of environ if mpm isn't threaded
* - we could allow modification of environ if variable isn't a CGI
* variable (still could cause problems)
*/
/*
* problems we are trying to solve:
* - environ is shared between threads
* + Perl does not serialize access to environ
* + even if it did, CGI variables cannot be shared between threads!
* problems we create by trying to solve above problems:
* - a forked process will not inherit the current %ENV
* - C libraries might rely on environ, e.g. DBD::Oracle
*/
https://stackoverflow.com/questions/-100000783
复制相似问题