This app leverages a PHP session handler for a memcached instance by providing a
binding of type
php-memcached-session
. In order to use this app, you will need to set up a memcached
instance and enable basic container to container networking as shown below.
-
Run a Memcached instance, in this example we are using the default Memcached Docker image:
docker run -it -p 6379 memcached:latest
-
Get the Memcached 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. Also create aservers
file with the IP address in it as well. The binding directory should now contain:type
:php-memcached-session
host
: <IP address from step 2>servers
: <IP address from step 2> -
Build the app with the service binding:
pack build php-memcached-handler-sample \
--env BP_PHP_WEB_DIR=htdocs \
--env SERVICE_BINDING_ROOT=/bindings \
--volume $PWD/binding:/bindings/php-memcached-session \
--buildpack paketo-buildpacks/php \
--builder paketobuildpacks/builder-jammy-full
docker run --interactive --tty --env PORT=8080 --publish 8080:8080 php-memcached-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 and see the
page count increment.
The Paketo PHP buildpack requires the Full Jammy Stack. See stack docs for more details