RoadRunner
  • 🟠General
    • What is RoadRunner?
    • Features
    • Quick Start
    • Installation
    • Configuration
    • Contributing
    • Upgrade and Compatibility
  • 👷PHP Worker
    • Worker
    • Workers pool
    • Developer mode
    • Code Coverage
    • Debugging
    • Environment
    • Manual workers scaling
    • Auto workers scaling
    • RPC
  • 🟢Customization
    • Building RR with a custom plugin
    • Integrating with Golang Apps
    • Writing a Middleware
    • Writing a Jobs Driver
    • Writing a Plugin
    • Events Bus
  • 🔌Plugins
    • Intro into Plugins
    • Centrifuge (WebSockets)
    • Service (Systemd)
    • Configuration
    • Server
    • Locks
    • gRPC
    • TCP
  • 🌐Community Plugins
    • Intro into Community Plugins
    • Circuit Breaker
    • SendRemoteFile
    • RFC 7234 Cache
  • 🔵App Server
    • Production Usage
    • RoadRunner with NGINX
    • RR as AWS Lambda
    • Docker Images
    • CLI Commands
    • Systemd
  • 🔐Key-Value
    • Intro into KV
    • Memcached
    • In-Memory
    • BoltDB
    • Redis
  • 📦Queues and Jobs
    • Intro into Jobs
    • Google Pub/Sub
    • Beanstalk
    • In-Memory
    • RabbitMQ
    • BoltDB
    • Kafka
    • NATS
    • SQS
  • 🕸️HTTP
    • Intro into HTTP
    • Headers and CORS
    • Proxy IP parser
    • Static files
    • X-Sendfile
    • Streaming
    • gzip
  • 📈Logging and Observability
    • OpenTelemetry
    • HealthChecks
    • Access Logs
    • AppLogger
    • Metrics
    • Grafana
    • Logger
  • 🔀Workflow Engine
    • Temporal.io
    • Worker
  • 🧩Integrations
    • Migration from RRv1 to RRv2
    • Spiral Framework
    • Yii
    • Symfony
    • Laravel
    • ChubbyPHP
  • 🧪Experimental Features
    • List of the Experimental Features
  • 🚨Error codes
    • CRC validation failed
    • Allocate Timeout
  • 📚Releases
    • v2025.1.1
    • v2025.1.0
    • v2024.3.5
    • v2024.3.4
    • v2024.3.3
    • v2024.3.2
    • v2024.3.1
    • v2024.3.0
Powered by GitBook
On this page
  • Setting Env Variables
  • Dotenv
  • Default Env variables in PHP Workers
  • What's Next?

Was this helpful?

Edit on GitHub
  1. PHP Worker

Environment

PreviousDebuggingNextManual workers scaling

Last updated 1 year ago

Was this helpful?

Environment variables allow you to separate configuration data from your application code, making it more maintainable and portable.

RoadRunner supports the expansion of environment variables using the ${VARIABLE} or $VARIABLE syntax in a configuration file and CLI commands. You can use this feature to dynamically set values based on the current environment, such as database connection strings, API keys, and other sensitive information.

You can specify a default value for an environment variable using the ${VARIABLE:-DEFAULT_VALUE} syntax. For example, if you want to use a default value of 8080 for the HTTP_PORT environment variable if it is not defined or is empty, you can use the following configuration:

.rr.yaml
http:
  address: 127.0.0.1:${HTTP_PORT:-8080}

You can find more information on Bash Environment Variable Defaults in the .

This allows you to easily customize the configuration based on your specific environment without changing the configuration file itself.

Here's an example of a docker-compose.yaml file that redefines the HTTP_PORT for an RR service:

docker-compose.yaml
version: '3.8'

services:
  app:
    image: xxx
    environment:
      - HTTP_PORT=8081

Setting Env Variables

You can set environment variables for PHP workers by defining them in the server.env section of the RoadRunner configuration file. These variables will be applied to all workers when they are started by the server.

Here's an example:

.rr.yaml
server:
  command: "php worker.php"
  env:
     APP_RUNTIME: prod

In this example, when RoadRunner starts a PHP worker, it will set the APP_RUNTIME environment variable to prod.

All environment variable keys will be automatically converted to uppercase.

Dotenv

RoadRunner supports reading environment variables from .env files, which are typically used to store sensitive or environment-specific variables outside your codebase.

To read environment variables from an .env file, you can use the --dotenv CLI option when starting RoadRunner.

./rr serve --dotenv /var/www/config/.env

Default Env variables in PHP Workers

RoadRunner comes with a set of default environment (ENV) values that facilitate proper communication between the PHP process and the server. These values are automatically available to workers and can be used to configure and manage various aspects of the worker's operation.

Here's a list of the default ENV values provided by RoadRunner:

Key
Description

RR_MODE

Identifies what mode worker should work with (http, temporal, grpc, jobs, tcp, centrifuge, etc.)

RR_RPC

Contains RPC connection address when enabled.

RR_RELAY

pipes or tcp://..., depends on server relay configuration.

RR_VERSION

RoadRunner version started the PHP worker (minimum 2023.1.0)

These default environment values can be used within your PHP worker to configure various settings and adapt the worker's behavior according to the specific requirements of your application.

What's Next?

See how these variables are used in the to determine the Environment.

- Learn how to use environment variables in your RoadRunner configuration.

👷
Bash Reference Manual
spiral/roadrunner-worker
Environment variables