Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP][POC] Docker: Set two Memcached servers #6

Draft
wants to merge 2 commits into
base: feature/docker/memcached
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function registerBundles()
new EzSystems\EzPlatformEnterpriseEditionInstallerBundle\EzPlatformEnterpriseEditionInstallerBundle(),
new EzSystems\EzPlatformWorkflowBundle\EzPlatformWorkflowBundle(),
// Application
new MultipleMemcachedBundle\MultipleMemcachedBundle(),
new AppBundle\AppBundle(),
];

Expand Down
14 changes: 14 additions & 0 deletions app/config/cache_pool/cache.multiple.memcached.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
services:
cache.multiple.memcached:
parent: cache.adapter.memcached
tags:
- name: cache.pool
clearer: cache.app_clearer
provider: cache.multiple_memcached_provider
namespace: '%cache_namespace%'

cache.multiple_memcached_provider:
class: \Memcached
factory: ['MultipleMemcachedBundle\Component\Cache\Adapter\MultipleMemcachedAdapter', 'createConnection']
arguments:
- '%cache_dsn%'
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
},
"autoload": {
"psr-4": {
"MultipleMemcachedBundle\\": "src/MultipleMemcachedBundle/",
"AppBundle\\": "src/AppBundle/"
},
"classmap": [ "app/AppKernel.php", "app/AppCache.php" ]
Expand Down
6 changes: 3 additions & 3 deletions docker-compose.bash
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
set -e;

# Persistence Cache and Session Handler
CACHE_AND_SESSION_HANDLER=tagaware.filesystem
CACHE_AND_SESSION_HANDLER=memcached

while (( "$#" )); do
case "$1" in
Expand Down Expand Up @@ -56,8 +56,8 @@ if [[ 'redis' == "$CACHE_AND_SESSION_HANDLER" ]]; then
sed -i '' -e "s/CACHE_AND_SESSION_PORT/6379/" app/config/parameters.yml;
UNUSED_CONTAINER_LIST="memcached";
elif [[ 'memcached' == "$CACHE_AND_SESSION_HANDLER" ]]; then
sed -i '' -e "s/CACHE_AND_SESSION_HOST/memcached/" app/config/parameters.yml;
sed -i '' -e "s/CACHE_AND_SESSION_PORT/11211/" app/config/parameters.yml;
# sed -i '' -e "s/CACHE_AND_SESSION_HOST/memcached/" app/config/parameters.yml;
# sed -i '' -e "s/CACHE_AND_SESSION_PORT/11211/" app/config/parameters.yml;
UNUSED_CONTAINER_LIST="redis";
else # tagaware.filesystem
sed -i '' -e "s/imports://" app/config/parameters.yml;
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ services:

redis:
image: redis:3.2
memcached:
memcached1:
image: memcached
memcached2:
image: memcached

mariadb:
Expand Down
5 changes: 3 additions & 2 deletions docker/apache/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM debian:10
MAINTAINER [email protected]

ARG symfony_env=dev
ARG session_save_handler=tagaware.filesystem
ARG session_save_handler=memcached
ENV SYMFONY_ENV=$symfony_env

ENV DEBIAN_FRONTEND noninteractive
Expand Down Expand Up @@ -49,7 +49,8 @@ RUN mkdir /run/php && touch /var/log/php7.3-fpm.log
RUN if [[ 'redis' == $session_save_handler ]]; then \
echo "\n; Redis as session handler\nphp_value[session.save_handler] = redis\nphp_value[session.save_path] = \"tcp://redis:6379\"" >> /etc/php/7.3/fpm/pool.d/www.conf; \
elif [[ 'memcached' == $session_save_handler ]]; then \
echo "\n; Memcached as session handler\nphp_value[session.save_handler] = memcached\nphp_value[session.save_path] = \"memcached:11211\"" >> /etc/php/7.3/fpm/pool.d/www.conf; \
echo "\n; Memcached as session handler\nphp_value[session.save_handler] = memcached\nphp_value[session.save_path] = \"memcached1:11211,memcached2:11211\"" >> /etc/php/7.3/fpm/pool.d/www.conf; \
echo "php_value[memcached.sess_number_of_replicas] = 1\nphp_value[memcached.sess_lock_retries] = 10\nphp_value[memcached.sess_lock_expire] = 900" >> /etc/php/7.3/fpm/pool.d/www.conf \
fi;
# Apache: FastCGI Module & PHP-FPM Configuration
RUN a2enmod proxy_fcgi setenvif rewrite \
Expand Down
10 changes: 4 additions & 6 deletions docker/apache/parameters.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
imports:
- { resource: cache_pool/cache.CACHE_AND_SESSION_HOST.yml }
- { resource: cache_pool/cache.multiple.memcached.yml }

parameters:
#TODO: May move all this to .env file or Dockerfile
Expand All @@ -11,12 +11,10 @@ parameters:
env(HTTPCACHE_PURGE_SERVER): http://varnish
#env(HTTPCACHE_VARNISH_INVALIDATE_TOKEN): docker

# https://doc.ezplatform.com/en/2.5/guide/persistence_cache/
env(CACHE_POOL): cache.CACHE_AND_SESSION_HOST
env(CACHE_DSN): CACHE_AND_SESSION_HOST
# https://doc.ezplatform.com/en/2.5/guide/sessions/
env(CACHE_POOL): cache.multiple.memcached
env(CACHE_DSN): memcached://memcached1:11211?weight=67,memcached://memcached2:11211?weight=33
ezplatform.session.handler_id: ~
env(SESSION_SAVE_PATH): tcp://CACHE_AND_SESSION_HOST:CACHE_AND_SESSION_PORT
env(SESSION_SAVE_PATH): memcached1:11211,memcached2:11211

env(DATABASE_HOST): mariadb
env(DATABASE_PASSWORD): root
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace MultipleMemcachedBundle\Component\Cache\Adapter;

use \Symfony\Component\Cache\Adapter\MemcachedAdapter;
use Symfony\Component\Cache\Exception\InvalidArgumentException;
use Symfony\Component\Cache\Traits\MemcachedTrait;

class MultipleMemcachedAdapter extends MemcachedAdapter
{
public static function createConnection($servers, array $options = []): \Memcached
{
if (\is_string($servers)) {
$servers = \explode(',', $servers);
foreach ($servers as $serverIndex => $server) {
if (0 !== strpos($server, 'memcached://')) {
$servers[$serverIndex] = "memcached://$server";
}
}
}
if (!\is_array($servers)) {
throw new InvalidArgumentException(sprintf('Unsupported Server/DSN list: %s.', var_export($servers, true)));
}
return MemcachedTrait::createConnection($servers, $options);
}
}
9 changes: 9 additions & 0 deletions src/MultipleMemcachedBundle/MultipleMemcachedBundle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace MultipleMemcachedBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;

class MultipleMemcachedBundle extends Bundle
{
}