开发者

does PUTENV affect the variable in other scripts

开发者 https://www.devze.com 2023-03-30 10:26 出处:网络
If I se开发者_如何学Ct a variable using putenv, will other scripts be affected by this. My understanding is that it is script specific, is that correct? if two different scripts are running at the sa

If I se开发者_如何学Ct a variable using putenv, will other scripts be affected by this.

My understanding is that it is script specific, is that correct? if two different scripts are running at the same time on the server, will it affect the other script?


Yes, the env vars are specific to each particular invocation of a program/script. Just like each program can have its own working directory, its own stdin/stdout/stderr, etc... One script's environment cannot affect another's, unless they're in a parent/child relationship.


No, other scripts will not be affected.

The environment variable will only exist for the duration of the current request.

The following sample code can be run using the PHP CLI utility.

<?php
putenv("FOO=bar");
print("PHP says FOO=" . getenv("FOO") . "\n");
?>

Here is the output of the program and the resulting environment.

$ php putenv.php; echo echo says FOO=$FOO
PHP says FOO=bar
echo says FOO=
0

精彩评论

暂无评论...
验证码 换一张
取 消