homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
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

 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)



 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...]


 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 . . .


 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. )



 7:39 pm on Jun 1, 2012 (gmt 0)

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

$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.


 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:


If not, check variables_order:
and track_vars too.

If it's not those PHP configuration directives than it may be security-related:

And safe_mode and openbase_dir are the first that always come to mind ...

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