Run Symfony 3 without cache when predis is down - php

In my symfony project i use the predis package to connect with redis;
In my config.yml :
doctrine_cache:
providers:
redis_cache:
predis:
host: 127.0.0.1
port: 6379
In my config_dev.yml :
doctrine_cache:
providers:
redis_cache:
type: array
This works fine,
However, when the redis server is down, my production doesnt work either.
Is there a way for me to go through redis, but when the connection fails just act like there is no caching, just like in dev?
Thanks in advance, let me know if i need to clarify my question more.

Related

Expected int, but got string for redis port

I have this configuration for docker:
# docker-compose.yml
environment:
REDIS_SERVER: redis
REDIS_PORT: 6379
And then in symfony I use this to configure parameters:
# parameters.yml
redis_port: %env(REDIS_PORT)%
And then I use the parameter to configure Picmore's cache:
```yaml
# pimcore.yml
cache:
pools:
redis:
enabled: true
connection:
port: '%redis_port%'
But I get the error
Invalid type for path "pimcore.cache.pools.redis.connection.port". Expected int, but got string.
The error is clear but I can't solve it, I tried different options:
redis_port: '%env(REDIS_PORT)%'
redis_port: '%env(int:REDIS_PORT)%'
But I get the same error. How can I fix this?
You are using Symfony 3.3, but the int environment variable preprocessor was not added until Symfony 3.4, according to this.
I don't think you'll be able to use env vars to configure this value, since environment variables are strings by default.
Your options are to either use different parameters files for different environment, as things used to be done back then (which I understand can be inconvenient when using containers); or upgrade to a more recent version of Symfony.

Symfony 2.8 - SQL: No such file or directory in "test" environment only

I'm really struggling to get this issue fixed.
I have several Symfony projects I have been working on for months. Since last week, the "test" environment does not work anymore. It just cannot connect to the Mysql DB. This issue is present throughout all Symfony projects. The database config has not been changed and was working perfectly until last week. There is, and always was, a separate DB for the test environment. I did not update any dependencies or something. The weirdest thing is, that all is fine in prod or dev environment.
It really sucks, not being able to run tests locally, so I hope for your expertise!
Thanks in advance and cheers!
config_test.yml:
doctrine:
dbal:
host: localhost
dbname: rims_test
user: root
password:
Solved! alexander-schranz and johannes-wachter from the Sulu.io team provided me with this solution. Thanks a lot!
The solution was to remove a part of the test config:
config_test.yml: BEFORE
doctrine:
dbal:
host: localhost
dbname: rims_test
user: root
password:
config_test.yml: AFTER (Working again!)
doctrine:
dbal:
dbname: rims_test

Symfony 3.3 cache exception Memcached >= 2.2.0 is required

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

how to cache symfony partial in memcache?

We are using symfony 1.4 on our development machine
traditional way to cache partial in symfony is by editing cache.yml
something:
enabled: true
lifetime: true
this will store cache on the disk
but we want to store cache on memcache instead on disk.
so, the question is how to cache symfony partial in memcache
Symfony partial cache work like all other cache in symfony: it refers to view_cache part of apps/frontend/config/factories.yml.
For example, if you want to store your cache in SQLite database:
all:
view_cache:
class: sfSQLiteCache
param:
database: %SF_TEMPLATE_CACHE_DIR%/cache.db
So if you want to store these information into Memcached, you should use the sfMemcacheCache.class.php class:
all:
view_cache:
class: sfMemcacheCache
param:
servers:
server1:
host: localhost
port: 11211
persistent: true
OR
all:
view_cache:
class: sfMemcacheCache
param:
host: localhost
port: 11211
persistent: true

Symfony2 / Doctrine2 can't connect to IBM DB2 database using ibm_db2 client

I'm having an issue with Doctrine2 that seems like a bug but I can't find anyone else on Google with the same problem. I'm hoping somewhere here has experienced this problem and knows how to solve it.
Basically I'm trying to connect to a DB2 database. I prefer to use the ibm_db2 client as it's supposed to be better and faster (than PDO_IBM or PDO_ODBC). I've installed the client and tested it. Everything seems to work there. But when I use Doctrine I get the following error:
Notice: Undefined index: protocol in
...[my folders].../vendor/doctrine-dbal/lib/Doctrine/DBAL/Driver/
IBMDB2/DB2Driver.php line 54
So in that file it's looking for $params['protocol'] which seems to have no defaults. So in config.yml I tried this:
# Doctrine Configuration
doctrine:
dbal:
default_connection: default
driver: %database_driver%
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
protocol: TCPIP
But when I do that it complains that protocol is an undefined configuration option (and looking through the DependencyInjection stuff it doesn't appear anywhere in there.)
However: if I hard-code TCPIP into the Driver file where the error occurs ... it all works. This is undesirable since it involves changing the vendor supplied file. Has anyone found a way to properly specify the protocol in configuration?
Eventually you're going to run into licensing issues using ibm_db2 as noted here. PDO or ODBC are going to be your only free ways to go. IBM requires DB Connect to use ibm_db2 db2_connect() stuff.

Categories