首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >工人MPM下mod_perl中的进程内协调?

工人MPM下mod_perl中的进程内协调?
EN

Stack Overflow用户
提问于 2018-09-20 00:06:28
回答 2查看 0关注 0票数 0

我需要在mod_perl中做一些简单的时区计算。DateTime不是一个选项。我需要做的是通过设置$ ENV {TZ}并使用localtime和POSIX :: mktime轻松完成,但在线程MPM下,我需要确保一次只有一个线程与环境混淆。(我不关心本地时间的其他用途等)

如何使用互斥锁或其他锁定策略来序列化(在非编组意义上)对环境的访问?我看过的文档并不能很好地解释如何为这个用途创建一个互斥锁。也许有些东西,我只是没有了解你如何创建互斥体。

更新:是的,我知道需要使用Env :: C来设置TZ。

EN

Stack Overflow用户

发布于 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)中有一些注释:

代码语言:javascript
复制
/* * 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
 */
票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100000783

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档