简体   繁体   English

Windows上PHP中插件的Env变量

[英]Env variables for plugins in PHP on Windows

I am running PHP on Windows. 我在Windows上运行PHP。 PHP plugins on Windows are just DLL's in an extensions folder, and I can do little to configure these plugins. Windows上的PHP插件只是扩展文件夹中的DLL,我无法配置这些插件。

For example, the ADAP plugin (which is OpenLDAP itself) has settings that I can't change on runtime. 例如,ADAP插件(OpenLDAP本身)具有我无法在运行时更改的设置。 Luckily, OpenLDAP allows me to change some of these settings by messing with the environment variables. 幸运的是,OpenLDAP允许我通过弄乱环境变量来改变其中一些设置。 I tried setting them up on runtime by adding both: 我尝试通过添加两个来在运行时设置它们:

// this apparently works on Linux
putenv('VARIABLE=value');
// tried this one as well
$_ENV['VARIABLE'] = 'value';

But that didn't work. 但那没用。 I had to add that to Windows' environment variables (and that did work), but that's too much of a pain in the rear and will break the code when I move it. 我不得不将其添加到Windows的环境变量中(这确实有效),但是后面的太多痛苦并且在移动它时会破坏代码。 Is there a better way to do this or I'll have just to deal with it? 有没有更好的方法来做到这一点,或者我只是要处理它?

Thanks 谢谢

Try to set the environment variables before the dll extension is loaded. 尝试在加载dll扩展名之前设置环境变量。 That is, don't load the dll via php.ini, but use putenv() and afterwards dl(). 也就是说,不要通过php.ini加载dll,而是使用putenv()然后使用dl()。 Usually a DLL should share the environment variables with the main process, but you never know. 通常DLL应该与主进程共享环境变量,但你永远不会知道。

Alternatively set any required options from within .htaccess using SetEnv . 或者使用SetEnv在.htaccess中设置任何所需的选项。 This is at least portable for Apache webservers. 对于Apache Web服务器来说,这至少是可移植的。 Come to think of it, you should also try apache_setenv() if you are running mod_php and not the FastCGI version. 想想看,如果你运行mod_php而不是FastCGI版本,你也应该尝试apache_setenv()

Btw, there have always been PHP bugs for putenv, http://bugs.php.net/50690 , might be the case here. 顺便说一句,putenv一直有PHP漏洞, http://bugs.php.net/50690 ,可能就是这里的情况。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM