This app leverages a PHP session handler for a redis instance by providing a
binding of type
php-redis-session
. In order to use this app, you will need to set up a redis
instance and enable basic container to container networking as shown below.
-
Run a Redis instance, in this example we are using the default Redis Docker image:
docker run -it -p 6379 redis:latest
-
Get the Redis container bridge network IP address:
docker inspect <container ID> | jq -r 'map(.NetworkSettings.Networks.bridge.IPAddress) []'
You should get something like172.17.0.2
back. -
Create a
host
file inside of the appbinding
directory with the value set to the IP address from step 2. The binding directory should now contain:type
:php-redis-session
host
: <IP address from step 2> -
Build the app with the service binding:
pack build php-redis-handler-sample \
--env BP_PHP_WEB_DIR=htdocs \
--env SERVICE_BINDING_ROOT=/bindings \
--volume $PWD/binding:/bindings/php-redis-session \
--buildpack paketo-buildpacks/php \
--builder paketobuildpacks/builder-jammy-full
docker run --interactive --tty --env PORT=8080 --publish 8080:8080 php-redis-handler-sample
You can observe the stored state from the session handler by reaching the app twice, using a cookie in the request.
curl localhost:8080 --cookie-jar /tmp/cookie
Observe the counter that displays the number of hits the page has had serving 1
.
curl localhost:8080 --cookie /tmp/cookie
Observe the counter that displays the number of hits the page has had serving2
.
Alternatively, view localhost:8080
in your browser a few times adn see the
page count increment.
The Paketo PHP buildpack requires the Full Jammy Stack. See stack docs for more details