homepage Welcome to WebmasterWorld Guest from 23.22.2.150
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Passing Environment Variables to Command Line Call
Brett_Tabke

WebmasterWorld Administrator brett_tabke us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4459033 posted 2:54 pm on May 29, 2012 (gmt 0)

Calling a perl script via back ticks out of php.

On server A the entire set of environment variables is available.

On server B, they are not.

Both are running Cpanel.

Both are running same set of scripts on each server.

Apache http env variables is what I am after in the perl program.

This issue ring a bell with anyone? (it is almost deja vu with me. seems I've run into this before)

 

eelixduppy

WebmasterWorld Senior Member eelixduppy us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4459033 posted 7:32 pm on May 29, 2012 (gmt 0)

The Apache environment variables are set by Apache itself. I do not think this is a PHP configuration issue, but I may be wrong.

How are you fetching the values -- $_SERVER[], getenv(), or apache_getenv()?


Also: [httpd.apache.org...]

rocknbil

WebmasterWorld Senior Member rocknbil us a WebmasterWorld Top Contributor of All Time 5+ Year Member



 
Msg#: 4459033 posted 4:25 pm on May 30, 2012 (gmt 0)

Apache http env variables is what I am after in the perl program.


And in perl of course you already know PHP's $_SERVER = Perl's %ENV . . . However . . . since it's the PHP script that's being requested, $_SERVER['REQUEST_URI'] (and referrer, etc.) will be available to the PHP script, but $ENV{'REQUEST_URI'} is not likely to be available to the Perl script because it's not being requested by a client, it's being "requested" by the PHP script. Is that what you mean? You'd pass the value as an argument vector in that case . . .

rlange



 
Msg#: 4459033 posted 2:51 pm on May 31, 2012 (gmt 0)

If you're only missing the Apache environment variables, the only thing I can think of is that PHP on Server A is running as an Apache module, while on Server B it's running as CGI.

I believe PHP running as CGI doesn't have access to Apache's environment variables, because the process isn't actually part of the Apache environment. (Edit: I'm sort of doubting this now. I can't find any confirmation. Bleh. )

--
Ryan

Brett_Tabke

WebmasterWorld Administrator brett_tabke us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4459033 posted 7:39 pm on Jun 1, 2012 (gmt 0)

in middle of php (a wordpress post with exec php mod on)


<?php
$output = `perl /public_html/webmasterworld/testfun.cgi`;
echo "$output";
?>

That runs fine on this server. The perl script has the entire environment there for it. I use that to death over on the pubcon site here because most of the substructure is still perl.

On another server, same script, same wordpress db - I get nothing for variables. I stumped. Something is running to block them.

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4459033 posted 11:48 pm on Jun 1, 2012 (gmt 0)

Things I would check first ... PHP ini setting for environment variables. Run a simple script to see if $_SERVER and/or $_ENV are getting populated:


<pre>
<?php
print_r($_SERVER);
print_r($_ENV);
?>
</pre>


If not, check variables_order:
[php.net...]
and track_vars too.

If it's not those PHP configuration directives than it may be security-related:
[php.net...]

And safe_mode and openbase_dir are the first that always come to mind ...
[php.net...]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved