I have a strange run-time problem. I have a fairly vanilla PHP 8.3 app with a custom Dockerfile. It runs fine locally and passes a bunch of automated integration tests.
The PHP code uses getenv('HOSTNAME') to get the name of the machine/container it is running in. This is used to mark a request as belonging to one of several handler/queue machines. This works fine locally in Docker, but in Fly it seems to return an empty string.
However if I shell into a machine, this variable is indeed set; I can see it with set | grep HOSTNAME. However, a one-liner fails to retrieve it:
So I had a quick shufti, and found that FLY_MACHINE_ID offers the same thing. I confirmed that it was available with set | grep FLY_MACHINE_ID. But here’s the weird thing; if I use it in PHP then it is indeed available:
Is there some mechanics that decide whether to expose an env var to the code running inside the VM? Unfortunately I can’t just set this in my TOML config, since the whole point is to use a unique machine name to help distinguish between machines.
Super, thank you both. I’ve been using Linux for donkeys’, and have not ever come across the distinction between the two types of variable. Very handy to know.