From 4087c70ec87302f71090a5282dab8b27c3fcb958 Mon Sep 17 00:00:00 2001 From: "R. Eric Wheeler" Date: Wed, 29 Mar 2017 15:18:01 -0700 Subject: [PATCH] Finish adding redis cache/session support --- app/AppKernel.php | 3 ++ app/config/config.yml | 57 ++++++++++++++++++++++++++++++++-- app/config/config_dev.yml | 7 +++++ app/config/config_prod.yml | 16 +++------- app/config/services.yml | 8 ++--- app/config/snc_redis.yml | 63 ++++++++++++++++++++++++++++++++++++++ composer.json | 4 ++- docker-compose.yml | 2 ++ web/config.php | 3 +- 9 files changed, 142 insertions(+), 21 deletions(-) create mode 100644 app/config/snc_redis.yml diff --git a/app/AppKernel.php b/app/AppKernel.php index 8f1caa3..16812c1 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -7,6 +7,7 @@ class AppKernel extends Kernel { public function registerBundles() { + $bundles = [ new Symfony\Bundle\FrameworkBundle\FrameworkBundle(), new Symfony\Bundle\SecurityBundle\SecurityBundle(), @@ -14,7 +15,9 @@ class AppKernel extends Kernel new Symfony\Bundle\MonologBundle\MonologBundle(), new Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle(), new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), + new Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), + new \Snc\RedisBundle\SncRedisBundle(), new Sikofitt\DoughnutWeddingBundle\SikofittDoughnutWeddingBundle(), ]; diff --git a/app/config/config.yml b/app/config/config.yml index d4ff0d2..0d88eba 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -4,6 +4,7 @@ imports: - { resource: parameters.yml } - { resource: security.yml } - { resource: services.yml } + - { resource: snc_redis.yml } # Put parameters here that don't need to change on each machine where the app is deployed # http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration @@ -11,8 +12,13 @@ parameters: locale: en framework: + cache: + app: cache.adapter.redis + system: cache.adapter.redis + default_redis_provider: "redis://redis" #esi: ~ - #translator: { fallbacks: ['%locale%'] } + translator: { fallbacks: ['%locale%'] } + secret: '%secret%' router: resource: '%kernel.root_dir%/config/routing.yml' @@ -28,8 +34,9 @@ framework: trusted_proxies: ~ session: # http://symfony.com/doc/current/reference/configuration/framework.html#handler-id - handler_id: session.handler.native_file - save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%" + handler_id: snc_redis.session.handler + #handler_id: session.handler.native_file + #save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%" fragments: ~ http_method_override: true assets: ~ @@ -59,10 +66,54 @@ doctrine: #path: '%database_path%' orm: + query_cache_driver: + type: predis + host: ~ + port: ~ + instance_class: ~ + class: ~ + id: ~ + namespace: doughnut_query_cache + cache_provider: 'predis' + metadata_cache_driver: + type: predis + host: ~ + port: ~ + instance_class: ~ + class: ~ + id: ~ + namespace: doughnut_metadata_cache + cache_provider: 'predis' + result_cache_driver: + type: predis + host: ~ + port: ~ + instance_class: ~ + class: ~ + id: ~ + namespace: doughnut_result_cache + cache_provider: 'predis' + second_level_cache: + region_cache_driver: + type: predis + host: ~ + port: ~ + instance_class: ~ + class: ~ + id: ~ + namespace: doughnut_region_cache + cache_provider: 'predis' + auto_generate_proxy_classes: '%kernel.debug%' naming_strategy: doctrine.orm.naming_strategy.underscore auto_mapping: true +doctrine_cache: + providers: + predis: + type: predis + namespace: doughnut_doctrine + # Swiftmailer Configuration swiftmailer: transport: '%mailer_transport%' diff --git a/app/config/config_dev.yml b/app/config/config_dev.yml index a616d33..9b3c82b 100644 --- a/app/config/config_dev.yml +++ b/app/config/config_dev.yml @@ -18,9 +18,16 @@ monolog: path: '%kernel.logs_dir%/%kernel.environment%.log' level: debug channels: ['!event'] + formatter: colored_line_formatter console: type: console channels: ['!event', '!doctrine'] + redis_logger: + type: service + id: snc_redis.monolog.handler + level: debug + + # uncomment to get logging in your browser # you may have to allow bigger header sizes in your Web server configuration #firephp: diff --git a/app/config/config_prod.yml b/app/config/config_prod.yml index 0c85b03..6dcdec9 100644 --- a/app/config/config_prod.yml +++ b/app/config/config_prod.yml @@ -1,21 +1,15 @@ imports: - { resource: config.yml } -#doctrine: -# orm: -# metadata_cache_driver: apc -# result_cache_driver: apc -# query_cache_driver: apc - monolog: handlers: main: type: fingers_crossed action_level: error - handler: nested - nested: - type: stream - path: '%kernel.logs_dir%/%kernel.environment%.log' - level: debug + handler: redis console: type: console + redis: + type: service + id: snc_redis.monolog.handler + level: debug diff --git a/app/config/services.yml b/app/config/services.yml index f15dc0e..4d0ec71 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -1,9 +1,9 @@ # Learn more about services, parameters and containers at # http://symfony.com/doc/current/service_container.html parameters: - #parameter_name: value services: - #service_name: - # class: AppBundle\Directory\ClassName - # arguments: ['@another_service_name', 'plain_value', '%parameter_name%'] + colored_line_formatter: + class: Bramus\Monolog\Formatter\ColoredLineFormatter + tags: + - { name: 'monolog.logger' } diff --git a/app/config/snc_redis.yml b/app/config/snc_redis.yml new file mode 100644 index 0000000..db1b409 --- /dev/null +++ b/app/config/snc_redis.yml @@ -0,0 +1,63 @@ +snc_redis: + clients: + default: + type: predis + alias: default + dsn: redis://redis + logging: '%kernel.debug%' + monolog: + type: predis + alias: monolog + dsn: redis://redis/5 + logging: false + options: + connection_persistent: true + cache: + type: predis + alias: cache + dsn: redis://redis/3 + options: + profile: 2.2 + connection_timeout: 10 + read_write_timeout: 30 + profiler_storage: + type: predis + alias: profiler_storage + dsn: redis://redis/10 + session: + type: predis + alias: session + dsn: redis://redis/4 + logging: true + session: + client: session + prefix: 'doughnut:session:' + monolog: + client: monolog + key: monolog + formatter: colored_line_formatter + profiler_storage: + client: profiler_storage + ttl: 3600 + doctrine: + metadata_cache: + client: cache + entity_manager: default + document_manager: default + namespace: 'doughnut:doctrine:metadata:' + result_cache: + client: cache + entity_manager: default + document_manager: default + namespace: 'doughnut:doctrine:result:' + query_cache: + client: cache + entity_manager: default + namespace: 'doughnut:doctrine:query:' + second_level_cache: + client: cache + entity_manager: default + namespace: 'doughnut:doctrine:second_level:' + swiftmailer: + client: default + key: swiftmailer \ No newline at end of file diff --git a/composer.json b/composer.json index a302028..fa70072 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "php": ">=7.1", "bramus/monolog-colored-line-formatter": "^2.0", "doctrine/doctrine-bundle": "^1.6", - "doctrine/doctrine-cache-bundle": "^1.2", + "doctrine/doctrine-cache-bundle": "^1.3", "doctrine/orm": "^2.5", "egulias/email-validator": "^2.1", "google/recaptcha": "^1.1", @@ -37,6 +37,7 @@ "ravenberg/uikit-bundle": "^1.0", "sensio/distribution-bundle": "^5.0", "sensio/framework-extra-bundle": "^3.0.2", + "snc/redis-bundle": "^2.0", "symfony/monolog-bundle": "^3.0.2", "symfony/polyfill-apcu": "^1.0", "symfony/security": "^3.2", @@ -46,6 +47,7 @@ "symfony/swiftmailer-bundle": "^2.3.10", "symfony/symfony": "3.2.*", "tedivm/stash": "^0.14.1", + "tedivm/stash-bundle": "^0.6.2", "twig/extensions": "^1.4", "twig/twig": "^1.0||^2.0" }, diff --git a/docker-compose.yml b/docker-compose.yml index 76b1f41..37b94c6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -21,6 +21,8 @@ services: volumes: - ./:/var/www - ./web:/var/www/html + links: + - redis restart: always environment: - "APP_ENV=development" diff --git a/web/config.php b/web/config.php index 4d4d131..69df43c 100644 --- a/web/config.php +++ b/web/config.php @@ -13,9 +13,9 @@ if (!isset($_SERVER['HTTP_HOST'])) { exit('This script cannot be run from the CLI. Run it from a browser.'); } + if (!in_array(@$_SERVER['REMOTE_ADDR'], array( '127.0.0.1', - '172.19.0.1', '::1', ))) { header('HTTP/1.0 403 Forbidden'); @@ -417,7 +417,6 @@ $hasMinorProblems = (bool) count($minorProblems);
Symfony Standard Edition
-