php7: Uncaught Exception: Could not gather sufficient random data
The installed php7 version (7.1.2) installed with the docker alpine:latest (3.5) has a serious bug that affects all functions that use a getrandom syscall (eg: random_bytes() and random_int())
Examples:
run --rm -it alpine sh -c "apk add -q -U php7 && php7 -r \"random_bytes(12);\""
PHP Fatal error: Uncaught Exception: Could not gather sufficient random data in Command line code:1
Stack trace:
#0 Command line code(1): random_bytes(12)
#1 {main}
thrown in Command line code on line 1
docker run --rm -it alpine sh -c "apk add -q -U php7 && php7 -r \"random_int(0, 1);\""
PHP Fatal error: Uncaught Exception: Could not gather sufficient random data in Command line code:1
Stack trace:
#0 Command line code(1): random_int(0, 1)
#1 {main}
thrown in Command line code on line 1
This issue appears to be fixed in newer php releases.
References:
- https://github.com/docker-library/php/issues/376
- https://github.com/php/php-src/commit/14c72cc5824d5fa472b79b7216a01be0918ccc5d
(from redmine: issue id 7146, created on 2017-04-14, closed on 2018-08-22)