Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] Configuring Jetty for FastCGI - and pass env. vars to PHP scripts

Hi,

On Tue, Mar 31, 2020 at 9:34 PM Alexander Farber
<alexander.farber@xxxxxxxxx> wrote:
> The above stuff works well, but now I am also trying to pass some configuration information to the few PHP scripts I am also running - and unfortunately this does not work - when I print($_ENV['COUNTRY'); in the PHP scripts, the env. variable is not there.

This is not possible since they belong to 2 different processes.
The one that has the env variables set is a Java process (Jetty), the
one that runs PHP is php-fpm.

> Is there please a way to pass the env. vars from Jetty process to the PHP scripts run through FastCGI?

This is currently not possible out of the box.

It is common, however, to pass FastCGI variables along with the
request, and these can be retrieved in PHP via e.g.
$_SERVER['COUNTRY'] or getenv('COUNTRY') but *not* $_ENV['COUNTRY'].

What we can do is to allow to configure init-param names in
FastCGIProxyServlet, and then we can read those names and forward them
to PHP.
Please file an issue at https://github.com/eclipse/jetty.project/issues.

Something like:

<Call name="setInitParameter">
  <Arg>envNames</Arg>
  <Arg>COUNTRY, DOMAIN, ...</Arg>
</Call>

and we call System.getenv("COUNTRY"), etc.

What you can do right now is to override this:

class FarberFCGIServlet extends FastCGIProxyServlet {
  protected void customizeFastCGIHeaders(Request proxyRequest,
HttpFields fastCGIHeaders) {
    super.customizeFastCGIHeaders(proxyRequest, fastCGIHeaders);
    fastCGIHeaders.put("COUNTRY", System.getenv("COUNTRY"));
    ...
  }
}

-- 
Simone Bordet
----
http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.


Back to the top