I am integrating redis in my symfony2. I used this tuts:
http://olegpuzanov.com/2015/02/01/using-redis-for-doctrine-caching-in-symfony2/
ClassNotFoundException in appDevDebugProjectContainer.php line 966: Attempted to load class "Redis" from the global namespace.
Did you forget a "use" statement?
here are my configuration:
snc_redis:
# configure predis as client
clients:
default:
type: predis
alias: default
dsn: redis://localhost
doctrine:
type: predis
alias: doctrine
dsn: redis://localhost
# configure doctrine caching
doctrine:
metadata_cache:
client: doctrine
entity_manager: Content
document_manager: default
result_cache:
client: doctrine
entity_manager: [Content]
query_cache:
client: doctrine
entity_manager: Content
and my query:
$query = $this->createQueryBuilder('c')
->select('c.id, c.title, c.sequence, c.sequence_count, c.category_sequence, c.unique_id, c.priority, c.status, c.created_at,c.kaltura_id')
->addSelect('o.slug as owner')
->addSelect('cat.slug as category')
->addSelect("group_concat(m.name SEPARATOR ',') AS media")
->addSelect("group_concat(a.name SEPARATOR ',') AS album")
->innerJoin('c.content_owner', 'o')
->innerJoin('c.category', 'cat')
->leftJoin('c.media', 'm')
->leftJoin('c.albums', 'a')
->groupBy('c.id')
->setResultCacheDriver($predis)
# set cache lifetime
->setResultCacheLifetime($cache_lifetime)
->getQuery()
->getArrayResult();`
also i registered the snc bundle in my app kernel.
please help
git clone https://github.com/phpredis/phpredis.git
cd phpredis
git checkout php7
phpize
./configure
make && make install
cd ..
rm -rf phpredis
See https://gist.github.com/hollodotme/418e9b7c6ebc358e7fda
enter image description here
If first time you use redis, You must uncomment redis extension for php config and restart your server. So your problem solved
Related
I am adding Memcached to my app and despite some very confusing setup and apparent duplicate it seemed to work, if only barely.
Then I needed to clear the cache after some changes using
./bin/console cache:clear --env=dev ( or =prod )
That's when I got the error:
[Symfony\Component\Cache\Exception\CacheException]
Memcached >= 2.2.0 is required
Well, according to phpinfo(), the Memcached version I've installed is 3.0.4, so I am not sure where that error is coming from.
EDIT: Adding that I am have also got the error below when attempting the cache:clear command:
PHP Fatal error: Class 'Memcached' not found in /Users/user/Sites/Symfony1/vendor/doctrine/doctrine-cache-bundle/Tests/Functional/Fixtures/Memcached.php on line 6
As said the configuration is not at all clear. There's apparent overlap and my research on SO and elsewhere did not help much.
Also, I am using the memcached adapter on the Controller like so:
use Symfony\Component\Cache\Adapter\MemcachedAdapter;
which comes from Symfony's cache component, which does not seem to require any configuration on config.yml.
In any case, here's the configuration cache wise.:
/app/config.yml
framework:
cache:
app: cache.adapter.memcached
default_memcached_provider: "memcached://127.0.0.1:11211"
...
orm:
...
entity_managers:
default:
metadata_cache_driver: memcached
result_cache_driver:
type: memcached
host: 127.0.0.1
port: 11211
instance_class: Memcached
query_cache_driver: memcached
doctrine_cache:
aliases:
mem_cached_meta: my_memcached_cache_metadata
mem_cached_query: my_memcached_cache_query
mem_cached_result: my_memcached_cache_result
providers:
my_memcached_cache_metadata:
type: memcached
namespace: metadata_cache_ns
aliases:
- mem_cached_meta
my_memcached_cache_query:
type: memcached
namespace: query_cache_ns
aliases:
- mem_cached_query
my_memcached_cache_result:
type: memcached
namespace: result_cache_ns
aliases:
- mem_cached_result
I am using Symfony 4.0.3 and I need connect to Oracle DB. I follow this instructions:
https://symfony.com/doc/current/doctrine.html
my .env file
DATABASE_URL=oci8://user:pwd#xxx.xxx.xxx.xxx:1521/something
host address is from tnsnames.ora -> HOST, something is from tnsnames.ora -> SERVICE_NAME
And after running command:
php bin/console doctrine:database:create
I get this error:
C:\Apache24\htdocs\myapp>
2018-01-25T12:58:47+00:00 [error] Error thrown while running command
"doctrine:d
atabase:create". Message: "Notice: Undefined index: dbname"
In AbstractOracleDriver.php line 125:
Notice: Undefined index: dbname
I am able to connect to DB by plain PHP, but through Symfony not. dbname is something from my connect url at .env file. This is set from tnsnames.ora.
It looks like the dbname parameter is not picked up from your environment variable / DBAL url.
To solve this quickly just use explicit configuration instead of URL for doctrine DBAL's configuration.
The full reference configuration can be found in the symfony documentation -
Doctrine DBAL Reference Configuration
The documentation for the Doctrine DBAL Oracle configuration can be found here.
config/packages/doctrine.yaml:
doctrine:
# [..]
dbal:
default_connection: oracle_db_1
connections:
oracle_db_1:
driver: 'oci8' # ... or 'pdo_oci'
dbname: '<dbname>'
host: '<host>'
port: '<port>'
user: '<user>'
password: '<password>'
If that works replace dbname, host, port etc. with container parameters (i.e. '%env(DATABASE_NAME)%') read from environment variables and add those to your .env file.
doctrine.yaml edited like this:
parameters:
# Adds a fallback DATABASE_URL if the env var is not set.
# This allows you to run cache:warmup even if your
# environment variables are not available yet.
# You should not need to change this value.
#env(DATABASE_URL): ''
doctrine:
dbal:
default_connection: default
connections:
default:
driver: 'oci8' # ... or 'pdo_oci'
dbname: 'dbname'
host: 'xxx.xxx.xxx.xxx'
port: '1521'
user: 'user'
password: 'pwd'
# With Symfony 3.3, remove the `resolve:` prefix
# url: '%env(resolve:DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
after command
php bin/console doctrine:database:create
I have same error.
2018-01-26T06:23:31+00:00 [error] Error thrown while running command "doctrine:d
atabase:create". Message: "Notice: Undefined index: dbname"
In AbstractOracleDriver.php line 125:
Notice: Undefined index: dbname
my dbname is same as I have in SQL Developer in SID item.
There is a bug in doctrine/dbal version <= 2.8.0.
Upgrade to doctrine/dbal to version 2.9.0 and it should start to work.
Here is the github pull request solving this issue:
https://github.com/doctrine/dbal/pull/3297
If you use the SERVICE_NAME for your connection, you can define the DATABASE_URL like this:
DATABASE_URL=oci8://user:pw#x.x.x.x:1521/?service=1&servicename=something&charset=AL32UTF8
I have an existing entity in a Symfony3 project that I am trying to add an entity manager to. My doctrine.yml file looks like this
doctrine:
dbal:
default_connection: default
connections:
default:
driver: pdo_mysql
host: localhost
port: 3306
dbname: fullstackdb
user: root
password: root
charset: UTF8
lego:
driver: pdo_mysql
host: localhost
port: 3306
dbname: fullstackdb
user: root
password: root
charset: UTF8
orm:
default_entity_manager: default
entity_managers:
auto_mapping: true
default:
connection: default
mappings:
lego:
connection: lego
mappings:
AppBundle: ~
However anytime I try to access this entity manager through php bin/console doctrine:database:create --connection=lego
, it says the manager does not exist! I'm not sure if I'm missing a step - the only thing I've done to create the manager is to make the yml file.
It doesn't show up when I run bin/console debug:container.
Grateful for any help!
1) You are using the same schema name (database name) on the same host in two different entity managers without schema_filters. This means that when you do an update to one of the entity managers it will attempt to delete the data of the other entity manager.
2) You are asking about a entity manager but in the command you are passing a connection.
3) Run php bin/console debug:container | grep doctrine
This will give you all the doctrine services. Update your question accordingly.
4) Provide the exact command and exact error you get so we can track it down to the origin
5) For a more information run the command in verbose mode adding -v at the end
6) Are you importing your doctrine.yml in your config.yml ?
I'm using SncRedisBundle with success locally but can't have it work using heroku.
Here is my config :
#config.yml
imports:
- { resource: heroku/parameters_heroku.php } #heroku cloud provider configuration's
snc_redis:
clients:
default:
type: predis
alias: default
dsn: "%redis_url%"
cache:
type: predis
alias: cache
dsn: "%redis_url%&database=1"
logging: false
session:
type: predis
alias: session
dsn: "%redis_url%&database=2"
task:
type: predis
alias: task
dsn: "%redis_url%&database=3"
doctrine:
type: predis
alias: doctrine
dsn: "%redis_url%&database=4"
session:
client: session
ttl: 10800 #le session expirera apres 3 heures
doctrine:
metadata_cache:
client: doctrine
entity_manager: default # the name of your entity_manager connection
document_manager: default # the name of your document_manager connection
result_cache:
client: doctrine
entity_manager: [default] # you may specify multiple entity_managers
query_cache:
client: doctrine
entity_manager: default
second_level_cache:
client: doctrine
entity_manager: default
monolog:
client: cache
key: monolog
swiftmailer:
client: default
key: swiftmailer
#heroku/parameters_heroku.php
<?php
$is_heroku = getenv("IS_HEROKU");//manually added : heroku config:set IS_HEROKU=1
if (!$is_heroku) {
return;
}
if ($redisUrl = getenv('REDIS_URL')) {
$aParsedRedisUrl = parse_url($redisUrl);
$redisConstructedDsn = 'redis://'.$aParsedRedisUrl['host'].':'.$aParsedRedisUrl['port'].$aParsedRedisUrl['path'].'?'.'password='.$aParsedRedisUrl['pass'].($aParsedRedisUrl['query'] ? '&'.$aParsedRedisUrl['query'] : ''); // le user ne sert pas : .'&user='.$aParsedRedisUrl['user']
$container->setParameter('redis_url', $redisConstructedDsn);
}
if I dump $redisConstructedDsn during the heroku build process, I've got something like that : redis://xxxxxx.compute-1.amazonaws.com:18839?password=foobar, so, it seem pretty compatible with predis doc
but the composer construction fails with a
remote: [Predis\Response\ServerException] remote:
NOAUTH Authentication required.
I can't find what I did wrong
problem solved :
initially I used this kind of syntax : dsn: "%redis_url%/3" wich is incompatible with heroku.
When I changed it to an acceptable format : "%redis_url%?database=3", I added bug elsewhere, so here is the simple correction in heroku/parameters_heroku.php
if ($redisUrl = getenv('REDIS_URL')) {
$container->setParameter('redis_url', $redisUrl);
}
some resources on the internet will say that predis isn't compatible with heroku's format, but they are old&wrong ;)
I start using Redis on me project (php-redis). Is a Symfony2 project and i found the:
https://github.com/snc/SncRedisBundle
I follow the installation process and i configured:
Some clients to store no-sql data and cache
Sessions storage
Doctrine metada, result and query cache
I create a new entity in a bundle and i fail because i create it at yml and i have all others with annotation system, so i delete yml format and create the annotation.
Every change i make on the annotation class (change the table name for example), is not affecting the schema or the database, even i recreate the database or try to execute cache:clear with all the options.
If i just comment the redis doctrine configuration lines, it works and i can see the changes on the schema.
Im maybe forgetting something, or i cant really find how to clean that doctrine redis cache.
¿I have to manually clean any position on the redis client use for caching?
Here is the configuration:
#Snc Redis Bundle
snc_redis:
clients:
d2a:
type: phpredis
alias: d2a
dsn: redis://localhost/1
cache:
type: phpredis
alias: cache
dsn: redis://localhost
logging: true
session:
client: d2a
prefix: redis_session
doctrine:
metadata_cache:
client: cache
entity_manager: default # the name of your entity_manager connection
document_manager: default # the name of your document_manager connection
result_cache:
client: cache
entity_manager: [default, read] # you may specify multiple entity_managers
query_cache:
client: cache
entity_manager: default
The easiest way but not the best one is to flush redis db with doctrine cache. Run
php app/console redis:flushdb --client=cache
(Not tested!) Another way is to setup doctrine metadata cache in doctrine config http://symfony.com/doc/current/reference/configuration/doctrine.html#caching-drivers
orm:
entity_managers:
# A collection of different named entity managers (e.g. some_em, another_em)
some_em:
metadata_cache_driver:
type: array # Required
host: ~
port: ~
instance_class: ~
class: ~