Hi all,
Recently I faced with one funny problem in PHP. Seems there is no way to run
a sub-process using shell_exec()
(or backticks), and pass there specially
crafted environment without affecting all running threads. As soon as I
update the environment, all other threads see the change. It's
multithreading nature to be running under the same process and share the
process environment, no problems so far, but there should be a way to run
sub-process with appropriate set of environment variables without affecting
all the threads.
Looks like for Win32 target, there is a popenex() function that is called by
shell_exec and this function has env parameter. I think it makes sense to
pass $_ENV in this argument. Certainly, $_ENV should be converted into array
of pointers.
Not sure if there is any way under unix other than using execXX() instead
of popen()
to get the same behaviour.
Thoughts?
-jv
2009/5/24 jvlad dmda@yandex.ru:
Hi all,
Recently I faced with one funny problem in PHP. Seems there is no way to run
a sub-process usingshell_exec()
(or backticks), and pass there specially
crafted environment without affecting all running threads. As soon as I
update the environment, all other threads see the change. It's
multithreading nature to be running under the same process and share the
process environment, no problems so far, but there should be a way to run
sub-process with appropriate set of environment variables without affecting
all the threads.Looks like for Win32 target, there is a popenex() function that is called by
shell_exec and this function has env parameter. I think it makes sense to
pass $_ENV in this argument. Certainly, $_ENV should be converted into array
of pointers.
Not sure if there is any way under unix other than using execXX() instead
ofpopen()
to get the same behaviour.Thoughts?
-jv
--
Does resource proc_open ( string $cmd , array $descriptorspec , array
&$pipes [, string $cwd [, array $env [, array $other_options ]]] ) for
the bill here?
--
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"
Recently I faced with one funny problem in PHP. Seems there is no way to
run
a sub-process usingexec()
(or backticks), and pass there specially
crafted environment without affecting all running threads. As soon as I
update the environment, all other threads see the change. It's
multithreading nature to be running under the same process and share the
process environment, no problems so far, but there should be a way to run
sub-process with appropriate set of environment variables without
affecting
all the threads.Looks like for Win32 target, there is a popenex() function that is called
by
shell_exec and this function has env parameter. I think it makes sense to
pass $_ENV in this argument. Certainly, $_ENV should be converted into
array
of pointers.
Not sure if there is any way under unix other than using execXX() instead
ofpopen()
to get the same behaviour.Thoughts?
-jv
Does resource proc_open ( string $cmd , array $descriptorspec , array
&$pipes [, string $cwd [, array $env [, array $other_options ]]] ) for
the bill here?
That's correct, but what to do with existing code that I need to use?
I don't want to replace all constructs like $a = $mycmd $cmdline
; with
many lines required for popenex(). I would not like this way even if only
one symbol
should be changed in the 3rd party code.
Why not to enhance semantic of exec()
and backticks functions? Why not to
run child process with copy of $_ENV[] instead of current process
envrironment?
With multithreading servers you can't change current process's enviroment
without affecting all the threads, but you can easily and safely change
$_ENV[].
-jv
Why not to enhance semantic of
exec()
and backticks functions? Why not to
run child process with copy of $_ENV[] instead of current process
envrironment?
Most likely because nobody uses (and cares of) multithreaded servers.
But a patch would be welcome, I guess.
--
Wbr,
Antony Dovgal
http://pinba.org - realtime statistics for PHP