I'm using symfony2 snc-redis bundle for caching.
On my server, redis has been installed and working correctly.
My problem is; when i try to clear or flush db with redis, all sites on my server that using redis, crashes. Giving internal server error because of prod env.
I'v tried to change redis configuration ports in my config.yml for every single site on my server but i think didn't work.
My sample snc-redis configuration:
snc_redis:
clients:
default:
type: predis
alias: default
dsn: redis://localhost
logging: %kernel.debug%
cache:
type: predis
alias: cache
dsn: redis://localhost/1
logging: true
cluster:
type: predis
alias: cluster
dsn:
- redis://127.0.0.1/5
- redis://127.0.0.2/6
- redis://pw#/var/run/redis/redis-1.sock/7
- redis://127.0.0.1:6379/8
options:
profile: 2.4
connection_timeout: 10
connection_persistent: true
read_write_timeout: 30
iterable_multibulk: false
throw_errors: true
cluster: Snc\RedisBundle\Client\Predis\Connection\PredisCluster
monolog:
type: predis
alias: monolog
dsn: redis://localhost/1
logging: false
options:
connection_persistent: true
session:
client: default
prefix: foo
use_as_default: true
doctrine:
metadata_cache:
client: cache
entity_manager: default
document_manager: default
result_cache:
client: cache
entity_manager: [default, read]
document_manager: [default, slave1, slave2]
namespace: "dcrc:"
query_cache:
client: cache
entity_manager: default
monolog:
client: monolog
key: monolog
swiftmailer:
client: default
key: swiftmailer
monolog:
handlers:
main:
type: service
id: monolog.handler.redis
level: debug
What i'm doing wrong? How can i get it work correctly and will not cause crashing.
My Redis Bundle for Symfon2:
Snc\RedisBundle\SncRedisBundle()
https://github.com/snc/SncRedisBundle
You can define prefix for each site like this:
snc_redis:
clients:
default:
dsn: "redis://localhost:6379"
options:
prefix : "site_name"
type: phpredis
alias: default
logging: %kernel.debug%
Note: You must to be considered to put this prefix to all clients ;)
Did you try to change client alias for every site ?
Related
I have a Sulu and a Sylius application which I am trying to integrate using the SuluSyliusBundle and RabbitMQ. I have added the following configs...
messenger.yaml
framework:
router:
resource: "%kernel.project_dir%/config/routing_%sulu.context%.yml"
messenger:
# Uncomment this (and the failed transport below) to send failed messages to this transport for later handling.
# failure_transport: failed
buses:
message_bus:
middleware:
- doctrine_transaction
- event_middleware
# Uncomment this (and the failed transport below) to send failed messages to this transport for later handling.
# failure_transport: failed
transports:
# https://symfony.com/doc/current/messenger.html#transport-configuration
# async: '%env(MESSENGER_TRANSPORT_DSN)%'
# failed: 'doctrine://default?queue_name=failed'
# sync: 'sync://'
routing:
# Route your messages to the transports
# 'App\Message\YourMessage': async
sulu_sylius_consumer.yaml
sylius_base_url: 'http://127.0.0.1:8001'
sylius_default_channel: 'default_channel'
sylius_oauth_config:
username: api
password: api
client_id: demo_client
client_secret: secret_demo_client
route_defaults_fallback:
view: 'templates/products/default'
firewall_provider_key: 'main'
The issue is that once I install the bundle and add these two configs, I get the following error
I believe this is being caused by the config in the messenger. I have added the routes to routes_admin.yaml as it is show in the documentation here:
routes_admin.yaml
app_events:
type: rest
resource: App\Controller\Admin\EventController
prefix: /admin/api
name_prefix: app.
options:
expose: true
app_event_registrations:
type: rest
resource: App\Controller\Admin\EventRegistrationController
prefix: /admin/api
name_prefix: app.
options:
expose: true
app_locations:
type: rest
resource: App\Controller\Admin\LocationController
prefix: /admin/api
name_prefix: app.
options:
expose: true
app_products:
type: rest
resource: App\Controller\Admin\ProductsController
prefix: /admin/api
name_prefix: app.
options:
expose: true
sulu_route:
mappings:
Sulu\Bundle\SyliusConsumerBundle\Model\RoutableResource\RoutableResource:
generator: schema
resource_key: product_content
options:
route_schema: "/products/{object.getCode()}"
routes_website.yaml
app.event:
path: /{_locale}/event/{id}
controller: App\Controller\Website\EventWebsiteController::indexAction
app.product:
path: /{_locale}/product/{id}
controller: App\Controller\Website\ProductWebsiteController::indexAction
What can I do to fix this error?
[edit: added routes_admin and routes_website yaml]
In Symfony4 I was using the following configuration for doctrine apcu caching:
doctrine:
orm:
auto_mapping: true
auto_generate_proxy_classes: false
metadata_cache_driver: apcu
query_cache_driver: apcu
result_cache_driver: apcu
After upgrading to Symfony5 I am getting an error:
Unknown cache of type "apc" configured for cache "metadata_cache" in entity
manager "default".
When changing the it to the following configuration it works:
doctrine:
orm:
auto_mapping: true
auto_generate_proxy_classes: false
metadata_cache_driver:
type: pool
pool: doctrine.system_cache_pool
query_cache_driver:
type: pool
pool: doctrine.system_cache_pool
result_cache_driver:
type: pool
pool: doctrine.result_cache_pool
But what kind of cache am I using now? And how can I switch it to apcu?
I had the same problem in Symfony 4.4.5
You should first install the Symfony Cache Component. Then, you should configure cache pools, services and doctrine cache as follows:
doctrine:
orm:
auto_generate_proxy_classes: false
metadata_cache_driver:
type: service
id: doctrine.system_cache_provider
query_cache_driver:
type: service
id: doctrine.system_cache_provider
result_cache_driver:
type: service
id: doctrine.result_cache_provider
services:
doctrine.result_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
public: false
arguments:
- '#doctrine.result_cache_pool'
doctrine.system_cache_provider:
class: Symfony\Component\Cache\DoctrineProvider
public: false
arguments:
- '#doctrine.system_cache_pool'
framework:
cache:
pools:
doctrine.result_cache_pool:
adapter: cache.adapter.apcu
doctrine.system_cache_pool:
adapter: cache.adapter.apcu
The above configration is taken from here.
I set a password on my local redis server, but it gives the following error:
"NOAUTH Authentication required."
How can I configure a Redis password in config.yml?
You can specify it in your dsn config.
snc_redis:
clients:
default:
type: predis
alias: default
dsn: 'redis://%redis_session_secret%#%redis_host%:%redis_port%'
For me this DSN format worked:
redis://127.0.0.1?password=yourpass
snc_redis:
clients:
default:
type: predis
alias: default
dsn: 'redis://127.0.0.1?password=yourpass'
Found in Wiki https://github.com/nrk/predis/wiki/Connection-Parameters
I am using FosElasticaBundle in a Symfony project. I configured my mappings but I get exception "expected a simple value for field [_id] but found [START_OBJECT]]".
I'd like to see the actual JSON created by FosElasticaBundle so I can directly test it against my ElasticSearch server, and understand more about the exception.
According to FosElastica documentation, everything should be logged when debug mode is enabled (i.e. in DEV environment) but I can't see this happening; I only see Doctrine queries, but no JSON.
How can I dump the JSON created by FosElasticaBundle?
Update: mappings
# FOSElasticaBundle
fos_elastica:
clients:
default: { host: %elasticsearch_host%, port: %elasticsearch_port%, logger: false }
indexes:
app:
types:
user:
mappings:
name: ~
surname: ~
persistence:
driver: orm
model: AppBundle\Entity\User
provider: ~
listener: ~
finder: ~
I think you should only set your logger to true instead of false
fos_elastica:
clients:
default:
host: %elasticsearch_host%
port: %elasticsearch_port%
logger: true <---- set true here
...
Perhaps anybody know, how to connect Doctrine to memcached pool, to use it as a cache driver?
I've check official bundle documentation, and lot of another sources, but didn't find any examples of such connection.
Also due to source code, I could not find any options to use pool, but perhaps I miss something.
Didn't test, but the following should work:
in app/config/parameters.yml, set/add
parameters:
memcached.servers:
- { host: 127.0.0.1, port: 11211 }
- { host: 127.0.0.2, port: 11211 }
in app/config/config.yml set/add
services:
memcache:
# class 'Memcache' or 'Memcached', depending on which PHP module you use
class: Memcache
calls:
- [ addServers, [ %memcached.servers% ]]
doctrine.cache.memcached:
class: Doctrine\Common\Cache\MemcachedCache
calls:
- [setMemcached, [#memcached]]
in app/config/config_prod.yml, set
doctrine:
orm:
metadata_cache_driver:
type: service
id: doctrine.cache.memcached
query_cache_driver:
type: service
id: doctrine.cache.memcached
result_cache_driver:
type: service
id: doctrine.cache.memcached
As I said, I can't test it, but this is the combination of several known-to-work techniques.
UPDATE: solution updated based on CrazySquirrel's findings.
Thanks lxg for your ideas. I've build right configuration using your ideas. Please find correct service definition below:
application config:
result_cache_driver:
type: service
id: doctrine.cache.memcached
service.yml
memcached:
class: Memcached
calls:
- [ addServers, [ %memcached_servers% ]]
doctrine.cache.memcached:
class: Doctrine\Common\Cache\MemcachedCache
calls:
- [setMemcached, [#memcached]]