php putenv lang,PHP putenv 用法 手册 | 示例代码

Environment variables are part of the underlying operating system's

way of doing things, and are used to pass information between a parent

process and its child, as well as to affect the way some internal

functions behave.  They should not be regarded as ordinary PHP

variables.

A primary purpose of setting environment variables in a PHP script is

so that they are available to processes invoked by that script using

e.g. the system() function, and it's unlikely that they would need to

be changed for other reasons.

For example, if a particular system command required a special value

of the environment variable LD_LIBRARY_PATH to execute successfully,

then the following code might be used on a *NIX system:

$saved=getenv("LD_LIBRARY_PATH");// save old value$newld="/extra/library/dir:/another/path/to/lib";// extra paths to addif ($saved) {$newld.=":$saved"; }// append old paths if anyputenv("LD_LIBRARY_PATH=$newld");// set new valuesystem("mycommand -with args");// do system command;

// mycommand is loaded using

// libs in the new path listputenv("LD_LIBRARY_PATH=$saved");// restore old value?>

It will usually be appropriate to restore the old value after use;

LD_LIBRARY_PATH is a particularly good example of a variable which it

is important to restore immediately, as it is used by internal

functions.

If php.ini configuration allows, the values of environment variables

are made available as PHP global variables on entry to a script, but

these global variables are merely copies and do not track the actual

environment variables once the script is entered.  Changing

$REMOTE_ADDR (or even $HTTP_ENV_VARS["REMOTE_ADDR"]) should not be

expected to affect the actual environment variable; this is why

putenv() is needed.

Finally, do not rely on environment variables maintaining the same

value from one script invocation to the next, especially if you have

used putenv().  The result depends on many factors, such as CGI vs

apache module, and the exact way in which the environment is

manipulated before entering the script.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值