Jump to content

Recommended Posts

I'm trying to create a nice clean $_ENV array as part of a Linux package management system I'm building with php, but Im having a hard time finding out when exactly it is that php's $_ENV array is built.

 

I have this bash file (env.sh).

 

#!/bin/bash

FOO="this is foo" ; export FOO

 

And this php file (envtest.php)

 

#!/usr/bin/bash
<?php

  exec("source env.sh");
  print_r($_ENV);

?>

 

Executing this...

 

$ ./envtest.php | grep FOO

 

I get nothing.

 

Executing...

 

$ FOO="this is foo" ; export FOO ; ./envtest.php

 

I still get nothing, but....

 

$ FOO="this is foo" ; export FOO ; php -r 'print_r($_ENV);' | grep FOO

 

returns...

 

[FOO] => this is foo

 

Anyone tried this before? Whats gives?

Link to comment
https://forums.phpfreaks.com/topic/50296-solved-sourcing-bash-variables-from-php/
Share on other sites

Yeah...its been a while since Ive posed a question. Anyway, Ive figured out the problem. It appears exec spawns another process, hence FOO is being set, but not within the same environment as my script.

 

It would also appear that there is no work around for this. Looks like I will be writing this application in Python instead. Not real impressed, but you get that on big jobs I suppose.

 

I was so hoping PHP might be up to the task.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.