# Configuring Memcache or Redis in local.php?

**URL:** <https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267>\
**Category:** Product Support\
**Created:** [March 6, 2023, 10:31am UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267 "2023-03-06T10:31:39Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [March 6, 2023, 10:31am UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/1 "2023-03-06T10:31:39Z")

</div>

I have seen a number of posts on the forum around the topic of how to install and configure Redis or Memcache with Mautic. Alas there is not one person that has put the solution. Also the documentation in Mautic docs seems super outdated and not explanatory at all: [Mautic Developer Documentation](https://developer.mautic.org/#delivered-adapters)

Some background of what I have done, yet I am unclear if it is working as I think my syntax is incorrect in local.php file (but it is not breaking it) - all done with the help of Google & chatGPT.

I am running on ubuntu 20.04 and did the following:  
Installed memcach and php module:  
sudo apt-get install memcached  
sudo apt-get install php-memcached  
restarted php7.4-fpm service  
added the following to my local.php

```auto
'cache' => array(
    'default' => array(
        'driver' => 'memcached',
        'options' => array(
            'servers' => array(
                array(
                    'host' => '127.0.0.1',
                    'port' => 11211,
                    'weight' => 100
                )
            )
        )
    )

```

Saved and exited.

However when I telnet into memcache server and check stats items I am not seeing anything being cached there…

```auto
telnet 127.0.0.1 11211
stats item

```

I I am not getting anything in response.

My hunch is my configuration in local.php is incorrect.

So anyone ever done this ?

Sorry have to tag you @silavapi 🙂

---

<div class="post-metadata">

**Author:** ![silavapi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/silavapi/32/7424_2.png) [@silavapi](https://forum.mautic.org/u/silavapi)\
**Post date:** [March 6, 2023, 11:21am UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/2 "2023-03-06T11:21:04Z")

</div>

Sadly this section has not yet been updated and brought over to the [new developer docs](https://mautic-developer.readthedocs.io/en/latest/components/cache.html) so I can’t help here!

If someone does have a working config, we are happy to help with documenting - the repo is here:

> **[GitHub - mautic/developer-documentation-new: The current Developer Documentation, served via...](https://github.com/mautic/developer-documentation-new)**
>
> The current Developer Documentation, served via Read the Docs

Here is the issue for the cache bundle:

> <https://github.com/mautic/developer-documentation-new/issues/59>
>
> We need to bring over the docs from the old docs relating to the Caching bundle,… ensure that it's up to date, and write it in RST format.
> 
> https://developer.mautic.org/#cache-bundle

Also worth noting this PR in the new end-user docs:

> <https://github.com/mautic/user-documentation/pull/138>
>
> \### Add an overview of local.php file based on a mautic 4.4.6 instance
> 
> We at …Leuchtfeuer created this local.php overview as a proposal for the user documentation of mautic 4.
> The impulse to create such an overview for mautic 4 was made by Sven Döring.
> Sven Döring offered and did already the first proofreading/review. 
> 
> Thanks a lot for that to Sven Döring.
> 
> So this PR Version has passed one time proofreading/review, but needs more by the community.
> 
> We would be glad, if somebody can do the additional review, so that it maybe could be part of the user documentation for mautic 4.

We have the entire configuration section documented now (see [here](https://mautic-documentation.readthedocs.io/en/latest/configuration/settings.html)) so that PR will also add the things which you can document in the local config file. We could add the specifics for setting up cache providers - I don’t know if this sits best in the dev docs or the end-user docs? What do you think @mikew?

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [March 6, 2023, 1:01pm UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/3 "2023-03-06T13:01:24Z")

</div>

I would think dev docs. I think the new docs looks super slick! Nice job.

Another things to add would be getting Mautic to work with Master/Master DB or Master/Slave on read and write.

My last post [Mautic, MySQL, Master & Slave, Read/Write](https://forum.mautic.org/t/mautic-mysql-master-slave-read-write/27264) still no replies though ☹ I am sure I am not the only one looking to do this

---

<div class="post-metadata">

**Author:** ![silavapi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/silavapi/32/7424_2.png) [@silavapi](https://forum.mautic.org/u/silavapi)\
**Post date:** [March 6, 2023, 1:38pm UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/4 "2023-03-06T13:38:45Z")

</div>

I think that @m.abumusa has been doing some work on the read/write and primary/secondary DBs, I recall seeing some PRs. Maybe he can help with the docs too 🙂

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [March 6, 2023, 4:11pm UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/5 "2023-03-06T16:11:18Z")

</div>

Thanks @silavapi appreciate that. Look forward to a reply from @m.abumusa

I am really hoping that someone (@ekke , @joeyk , @Yosu_Cadilla - sorry all had to tag you) can shed some light on the two main issues I am trying to face at the moment which are:  
implementing redis/memcached for Mautic including API  
setting up master/master master/slave environment.

---

<div class="post-metadata">

**Author:** ![m.abumusa](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/m.abumusa/32/741_2.png) [@m.abumusa](https://forum.mautic.org/u/m.abumusa)\
**Post date:** [March 6, 2023, 7:40pm UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/6 "2023-03-06T19:40:11Z")

</div>

@mikew I created two PRs for Master/Replica implementation, and I am using both of them in two production environments one that uses AWS RDS and the other one using Google Cloud MySQL.

> <https://github.com/mautic/mautic/pull/11792/>
>
> \<!-- ## Which branch should I use for my PR?
> 
> Assuming that:
> 
> a = current ma…jor release
> b = current minor release
> c = future major release
> 
> \* a.x for any features and enhancements (e.g. 5.x)
> \* a.b for any bug fixes (e.g. 4.4, 5.1)
> \* c.x for any features, enhancements or bug fixes with backward compatibility breaking changes (e.g. 5.x) --\>
> 
> | Q | A
> | -------------------------------------- | ---
> | Bug fix? (use the a.b branch) | \[\]
> | New feature/enhancement? (use the a.x branch) | X
> | Deprecations? | \[\]
> | BC breaks? (use the c.x branch) | \[\]
> | Automated tests included? | \[\] 
> | Related user documentation PR URL | mautic/mautic-documentation#... 
> | Related developer documentation PR URL | \[mautic/developer-documentation#...\](https://github.com/mautic/developer-documentation-new/pull/104) 
> | Issue(s) addressed | Fixes #... 
> 
> \<!--
> Additionally (see https://contribute.mautic.org/contributing-to-mautic/developer/code/pull-requests#work-on-your-pull-request):
> - Always add tests and ensure they pass.
> - Bug fixes must be submitted against the lowest maintained branch where they apply
> (lowest branches are regularly merged to upper ones so they get the fixes too.)
> - Features and deprecations must be submitted against the "4.x" branch.
> \--\>
> 
> \#### Description:
> 
> Right now there is method to split the connection between a master an slave databases, this PR solve this issue by splitting the connections to read-only and read-write connections
> 
> \<!--
> Please write a short README for your feature/bugfix. This will help people understand your PR and what it aims to do. If you are fixing a bug and if there is no linked issue already, please provide steps to reproduce the issue here.
> \--\>
> 
> \#### Steps to test this PR:
> 
> \<!--
> This part is really important. If you want your PR to be merged, take the time to write very clear, annotated and step by step test instructions. Do not assume any previous knowledge - testers may not be developers.
> \--\>
> 1. Open this PR on Gitpod or pull down for testing locally (see docs on testing PRs \[here\](https://contribute.mautic.org/contributing-to-mautic/tester))
> 2. Modify your \`local.php\` file to include a connection to a remote database that has replica configured, add the following parameter \`\`\`'db\_host\_ro'=\>'db'\`\`\` and change db with the name of the read replica of your database
> 3. Make sure that the read replica is getting queries
> 
> \<!--
> If you have any deprecations, list them here along with the new alternative.
> If you have any backwards compatibility breaks, list them here.
> \--\>

> <https://github.com/mautic/mautic/pull/12038>
>
> \<!-- ## Which branch should I use for my PR?
> 
> Assuming that:
> 
> a = current ma…jor release
> b = current minor release
> c = future major release
> 
> \* a.x for any features and enhancements (e.g. 5.x)
> \* a.b for any bug fixes (e.g. 4.4, 5.1)
> \* c.x for any features, enhancements or bug fixes with backward compatibility breaking changes (e.g. 5.x) --\>
> 
> | Q | A
> | -------------------------------------- | ---
> | Bug fix? (use the a.b branch) | \[\]
> | New feature/enhancement? (use the a.x branch) | \[\]
> | Deprecations? | \[X\]
> | BC breaks? (use the c.x branch) | \[\]
> | Automated tests included? | \[\] 
> | Related user documentation PR URL | mautic/mautic-documentation#... 
> | Related developer documentation PR URL | mautic/developer-documentation#... 
> | Issue(s) addressed | Fixes #... 
> 
> \<!--
> Additionally (see https://contribute.mautic.org/contributing-to-mautic/developer/code/pull-requests#work-on-your-pull-request):
> - Always add tests and ensure they pass.
> - Bug fixes must be submitted against the lowest maintained branch where they apply
> (lowest branches are regularly merged to upper ones so they get the fixes too.)
> - Features and deprecations must be submitted against the "4.x" branch.
> \--\>
> 
> \#### Description:
> 
> Some parts of Mautic used to have the ability to connect to read-only replicas, which makes sense for areas where we need to make read-only queries, this feature is important because it offloads the traffic from the read-write database servers.
> 
> I refactored the code to remove deprecations and tested it on a database server with a replica. this PR is related to #11792
> 
> \<!--
> Please write a short README for your feature/bugfix. This will help people understand your PR and what it aims to do. If you are fixing a bug and if there is no linked issue already, please provide steps to reproduce the issue here.
> \--\>
> 
> \#### Steps to test this PR:
> 
> \<!--
> This part is really important. If you want your PR to be merged, take the time to write very clear, annotated and step by step test instructions. Do not assume any previous knowledge - testers may not be developers.
> \--\>
> 1. Open this PR on Gitpod or pull down for testing locally (see docs on testing PRs \[here\](https://contribute.mautic.org/contributing-to-mautic/tester))
> 2. In \`local.php\` add a new entry \`db\_host\_ro =\> YOUR\_DATABASE\_SERVER\`
> 3. Run \`bin/console mautic:segments:update\` 
> 4. You should notice queries running on th read-only replica
> 
> \<!--
> If you have any deprecations, list them here along with the new alternative.
> If you have any backwards compatibility breaks, list them here.
> \--\>

As you can see from the file changes in PR #12038, I am only targeting a few areas of Mautic like reports, segments creation, and campaigns.

A better implementation may be in the future I can direct all the SELECT (except ones inside a COMMIT) statements to the read replica, all INSERT, UPDATE, DELETE, and COMMIT to the master node.

For the time being you can use these two PRs on both 5.x and 4.4 and it will work you and distribute the load in your database

---

<div class="post-metadata">

**Author:** ![m.abumusa](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/m.abumusa/32/741_2.png) [@m.abumusa](https://forum.mautic.org/u/m.abumusa)\
**Post date:** [March 6, 2023, 7:41pm UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/7 "2023-03-06T19:41:13Z")

</div>

I can start a PR on that regard, I will create an issue on the documentation repo so I do not forget that

---

<div class="post-metadata">

**Author:** ![m.abumusa](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/m.abumusa/32/741_2.png) [@m.abumusa](https://forum.mautic.org/u/m.abumusa)\
**Post date:** [March 6, 2023, 7:47pm UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/8 "2023-03-06T19:47:30Z")

</div>

@mikew regarding cache, the configuration variables are in this file

> <https://github.com/mautic/mautic/blob/992191338de0b39d1bdf8973e83a328563aa729f/app/bundles/CacheBundle/Config/config.php#L64>

---

<div class="post-metadata">

**Author:** ![Yosu\_Cadilla](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/yosu_cadilla/32/6206_2.png) [@Yosu\_Cadilla](https://forum.mautic.org/u/Yosu_Cadilla)\
**Post date:** [March 6, 2023, 9:04pm UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/9 "2023-03-06T21:04:19Z")

</div>

There was a group of 4-6 relatively young DEVOPS guys a few years ago, pushing this and other high level initiatives, like RabbitMQ integration and other similar stuff.

Since these community people are long gone, as almost everyone else from that time, no one is supporting those integrations anymore and they have degraded over time, meaning they will work out of the box on, let’s say M2.14 and probably on 2.26.5 , but after that, it’s a coin flip.

The initial Master/Slave integration in particular, I believe was written by Heath Dutton and was added to the main stable version of Mautic at the time, hence there is no independent repo, however this is the repo he used for most Mautic related things, so maybe you can find something buried there…

> **[Digital Media Solutions](https://github.com/TheDMSGroup)**
>
> Digital Media Solutions, Inc. (NYSE: DMS) is a leading provider of technology-enabled digital performance advertising solutions. - Digital Media Solutions

If you also take into account the 2 great engineers working at Mautic first and then at Acquia are also gone, there’s no one to clarify those long forgotten issues anymore.  
Glad to see that m.abumusa is picking the baton for M4 and M5, but if you are on M3, you might need to do a bit of scavenging…

**Personally, Master-Slave is of no use to me, reads and caches are plenty fast already, what I usually need is faster writes, for that I prefer to use master-master also called multi-master replication, commercial name: MariaDB Galera Cluster.**

Additional advantages of this type of setup:

- Every database in the cluster behaves just as a regular DB and no extra configuration is required for Mautic, the data replication is entirely managed by the DB layer over the local network. However, it is not as simple as master-slave to set it up on the MySQL level, but it’s also not rocket science.
- If you are using Multi-master, you can switch to one Mautic to another instantly, hence enabling full read-write High Availability to any number of nodes.
- You can define all nodes individually as read only, write only or write/read, and you can change that while the DB is running, whithout changing anything in Mautic.

---

<div class="post-metadata">

**Author:** ![Yosu\_Cadilla](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/yosu_cadilla/32/6206_2.png) [@Yosu\_Cadilla](https://forum.mautic.org/u/Yosu_Cadilla)\
**Post date:** [March 6, 2023, 9:17pm UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/10 "2023-03-06T21:17:33Z")

</div>

Thank you @m.abumusa.

Do you happen to know if there’s any documentation on how/if Mautic can handle in-memory (instead of in-disk) Symfony cache, which is available since Symfony 3 and as you shared, configurable on the local.php file?

Other related topics I am looking for info about (all related to the piece of code you shared) Is there any information somewhere about how to properly configure memcached or how to check if it is working?

Also for Redis and/or RabbitMQ: Do you know about any info about the configuration of these parameters that are on the local.php file?

It would be great if we could put together what parameters are usable or legacy or just history and do not do anything at all in current Mautic versions.  
If they are usable, how to configure them and how to check proper configuration is in place.  
And things like queues, can be used on ingress and egress, for example for page visit tracking and email queuing, some info about the supported use cases would be great too, don’t you agree?

---

<div class="post-metadata">

**Author:** ![Yosu\_Cadilla](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/yosu_cadilla/32/6206_2.png) [@Yosu\_Cadilla](https://forum.mautic.org/u/Yosu_Cadilla)\
**Post date:** [March 6, 2023, 9:55pm UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/11 "2023-03-06T21:55:37Z")

</div>

Oh! Since we are discussing documentation, The API docs were quite good a few years ago, but have had little to no love since. It also never had much useful documentation for non-Symfony programmers.

Currently, besides the very basic information available in the docs, the only place to be able to understand how the Mautic API really works is by looking at the code, which is not just PHP, but also Symfony based, making it anything from hard to impossible for programmers of the other 999 programming languages and frameworks out there to use the API.  
Additionally, the comments on the code are not very explicit, so sometimes it is hard, even looking at the code, to understand which parameters are mandatory.

API requirements are not documented and also not enforced in the code and error codes aren’t always returned, so if you want to do anything out of the basic few things, you need to test the limits and requirements “by hand”, not complaining, but also does not help Mautic’s image as a enterprise-ready solution…

Since an API’s reason to exist is to be able to communicate with other systems, regardless of language, stack, etc… it would make a lot of sense to have an API documentation that does a bit more than pointing to some PHP implementation of the API.

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [March 7, 2023, 7:20am UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/12 "2023-03-07T07:20:40Z")

</div>

Hi @m.abumusa - thanks for all the information.

I will start with memcached. Before reaching out I had done a bit of research and found a similar post on Redis: [Mautic Cache Redis config - #2 by mzagmajster](https://forum.mautic.org/t/mautic-cache-redis-config/20176/2)  
which references a fix for the Redis adapter :[Add RedisAdapter from Symfony 4 for CacheBundle by kuzmany · Pull Request #10889 · mautic/mautic · GitHub](https://github.com/mautic/mautic/pull/10889)

However after implementing a number of variations of the code placed above in my local.php file, I constantly get a broken Mautic.

I add the following code:

```auto
        'parameters' => (
                'cache_adapter' => 'mautic.cache.adapter.filesystem',
    'cache_prefix' => '',
    'cache_lifetime' => 86400,
    'cache_adapter_memcached' => (
        'servers' => ('memcached://localhost'),
        'options' => (
            'compression' => true,
            'libketama_compatible' => true,
            'serializer' => 'igbinary',
        ),
    ),

```

which results in the following error:

```auto
2023/03/07 07:12:10 [error] 3856#3856: *8874 FastCGI sent in stderr: "PHP message: PHP Notice - Undefined variable: inline - in file /var/www/mautic/offline.php - at line 77PHP message: PHP Notice: Undefined variable: inline in /var/www/mautic/offline.php on line 77PHP message: ParseError: syntax error, unexpected '=>' (T_DOUBLE_ARROW) - in file /var/www/ams/app/config/local.php - at line 769" while reading response header from upstream, client: 46.116.227.13, server: ams1.surge-ams.com, request: "GET /s/dashboard HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.4-fpm.sock:", host: "mtest.surge-ams.com", referrer: "https://mtest.surge-ams.com/s/login"

```

I have played around a lot with positioning the code and changing parenthesis with the square brackets however am unable to get it to not break Mautic.

I have checked and bot memcached and the php extension are installed and I am also able to telnet into memcached port and run stats items there to see if there is any data - unfortunately not, but the service is running.

Have you managed to get this work

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [March 7, 2023, 9:02am UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/13 "2023-03-07T09:02:15Z")

</div>

Hi @m.abumusa

I followed the first PR that you posted and updated the following files:

1. app/bundles/CoreBundle/Config/config.php
2. Created file: app/bundles/CoreBundle/Doctrine/Connection/PrimaryReadReplicaConnectionWrapper.php and crowned it to www-data:www-data
3. app/config/config.php

I then went and added the new parameter ‘db\_host\_ro’ =\> ‘10.10.0.3’, to my local.php file. I have confirmed that my slave is working and accessible

I restarted php7.4-fpm service.  
Cleared cache manually rm -rf var/cache/\*

When I tried to get to my Mautic instance, I get a broken site and in the error log I am seeing the following error:

```auto
2023/03/07 08:27:41 [error] 3856#3856: *9000 FastCGI sent in stderr: "PHP message: PHP Notice - Undefined variable: inline - in file /var/www/mautic/offline.php - at line 77PHP message: PHP Notice: Undefined variable: inline in /var/www/mauitc/offline.php on line 77PHP message: Symfony\Component\DependencyInjection\Exception\LogicException: Messenger support cannot be enabled as the Messenger component is not installed. Try running "composer require symfony/messenger". 

```

I am not using composer and running Mautic 4.4.4 so I went and installed this manually with this command:

```auto
sudo apt-get install php-symfony-messenger

```

Unfortunately I am still getting the same error message.

If I change back the config.php file back to the original my instance comes up again…

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [March 7, 2023, 9:06am UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/14 "2023-03-07T09:06:05Z")

</div>

Hey @Yosu_Cadilla ,

I have done some research, in order to test if memcached you can telnet 127.0.0.1 11211, once inside the terminal write: stats items and then you are meant to see keys and some other info there, for me I am not seeing anything.

---

<div class="post-metadata">

**Author:** ![Yosu\_Cadilla](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/yosu_cadilla/32/6206_2.png) [@Yosu\_Cadilla](https://forum.mautic.org/u/Yosu_Cadilla)\
**Post date:** [March 9, 2023, 2:54am UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/15 "2023-03-09T02:54:59Z")

</div>

> [@mikew](#):
>
> for me I am not seeing anything.

Yup, exactly.

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [March 9, 2023, 7:08am UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/16 "2023-03-09T07:08:50Z")

</div>

That is a pity to hear ☹

I think these two aspects are rather crucial for getting Mautic enterprise ready.

Some other things that might be of interest that I have done is setup an environment where I have created a nfs server and multiple Mautic workers sitting behind a load balancer for traffic, another instance outside of the load balancer but still pulling from the nfs server to run cron jobs, I was even thinking of splitting this up even further to have one server just taking care of campaign jobs and the other for segment update and sending. I am seeing on big installations even when there is ample resources campaigns triggers are being killed in the middle. I also setup an Redis server to share the php resources as well.

Currently giving better improvement but I believe if I was able to set up master-master or master-slave as well as memcache it could help as well.

Some other performance issues I have seen is API rate limit which I would be interested in hearing some thoughts around. I read an article where certain applications (not mautic), would have a separate server for api requestes on a different domain like [api.mautic.com](http://api.mautic.com)…

Interested in hearing what everyone thinks of the above. Maybe together we can come up with a nice cook book on best practices and howtos for big traffic sites.

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [March 16, 2023, 6:48am UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/17 "2023-03-16T06:48:24Z")

</div>

@escopecz I was wondering if you have some insights on this particular thread.

Would very much appreciate any pointers here.

---

<div class="post-metadata">

**Author:** ![escopecz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/escopecz/32/370_2.png) [@escopecz](https://forum.mautic.org/u/escopecz)\
**Post date:** [March 17, 2023, 11:30am UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/18 "2023-03-17T11:30:43Z")

</div>

I don’t have any experience with the QueueBundle. But there are discussions in Slack that the QueueBundle should be removed and replaced with [Messenger: Sync & Queued Message Handling (Symfony 5.4 Docs)](https://symfony.com/doc/5.4/messenger.html) which is already part of Mautic 5 dependencies. I haven’t seen any work started on that though.

---

<div class="post-metadata">

**Author:** ![mikew](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/mikew/32/5156_2.png) [@mikew](https://forum.mautic.org/u/mikew)\
**Post date:** [March 17, 2023, 1:39pm UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/19 "2023-03-17T13:39:36Z")

</div>

Thanks @escopecz for jumping in and giving some more info on this.

---

<div class="post-metadata">

**Author:** ![sfahrenkrog1](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/sfahrenkrog1/32/4583_2.png) [@sfahrenkrog1](https://forum.mautic.org/u/sfahrenkrog1)\
**Post date:** [July 21, 2024, 11:21am UTC](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267/20 "2024-07-21T11:21:15Z")

</div>

Hello Guys / @joeyk (you might like this one too)

I would like to share some tricks regarding performance tuning with redis and the symfony cache files.

This are Mautic 4 tricks. Don’t know about Mautic 5. But I think most of them might work with 5 too.

Note: I assume redis is already installed and running with default config.

**1) Activate the Redis Cache in local.php**

Status: Running in production

Add this to local.php and clear the cache:

```auto
    'cache_adapter' => 'mautic.cache.adapter.redis',
	'cache_adapter_redis' => array(
		'dsn' => 'redis://127.0.0.1:6379/0',
		'options' => array(
			'lazy' => '',
			'persistent' => '0',
			'persistent_id' => '',
			'timeout' => '30',
			'read_timeout' => '0',
			'retry_interval' => '0'
		)
	),
    'cache_prefix' => 'pa_',
    'cache_lifetime' => 3600,

```

Check if it’s working on the shell with command:  
redis-cli keys “pa\_\*”

(Make sure to do some page hits / traffic with mautic page tracking …)

Output should be like this:

 ![Bildschirmfoto 2024-07-21 um 12.57.21](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/0/0f35bbcec8da3b1fa33c9338bdec911eee5c723d.jpeg)

**2) Activate the doctrine metadata\_cache\_driver and query\_cache\_driver**

Status: Development / Running fine on my development server

We use 2 of 3 doctrine caches for metadata and query building. This should reduce the time for doctrine to build queries and classes.

Add a config\_override.php to app/config/ with this code:

```auto
<?php 

$container->loadFromExtension("doctrine", array(
    "orm" => array(
        "metadata_cache_driver" => array('type' => 'pool', 'pool'=>'doctrine.system_cache_pool'),
        "query_cache_driver" => array('type' => 'pool', 'pool'=>'doctrine.result_cache_pool'),
    )
));

$container->loadFromExtension("framework", array(
    "cache" => array(
        "pools" => array(
            "app.cache.redis" => array(
                "adapter" => "cache.adapter.redis",
                "public" => false,
                "default_lifetime" => 86400
            ),
            "doctrine.result_cache_pool" => array(
                "adapter" => "app.cache.redis"
            ),
            "doctrine.system_cache_pool" => array(
                "adapter" => "app.cache.redis"
            ),        
        )
    )
));

```

Check if it’s working on the shell with command:  
redis-cli keys “\*_CLASSMETADATA_\_”

(Make sure to do some page hits / traffic with mautic page tracking …)

Output should be like this:

 ![Bildschirmfoto 2024-07-21 um 13.02.08](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/3/3345ea92be297b17a4cb365c8b2b92f0547934b7.jpeg)

**3) Mount the mautic cache dir in a ram disk**

Status: Running in production

Harddrive is slower than ram. We place the whole mautic cache dir in a ram disk.  
But for mautic you don’t need to change any source code or configuration.

Add a line to /etc/fstab with:

tmpfs /home/m/web/m.dev.testserver.online/public\_html/app/cache/prod tmpfs defaults,noatime,nosuid,nodev,noexec,mode=1777,size=60M 0 0

and do  
mount -a

Check with shell command:  
df -h

Output should be like this:

 ![Bildschirmfoto 2024-07-21 um 13.05.25](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/0/0340eab24ea7c11e5ce33b09174ae5342b592f1e.png)

**4) Place a static copy of the mtc.js file in the mautic document root**

Status: Running in production

Mautic mtc.js is processed by php. This is slower than having a static copy in the document root.

You can do via shell from the mautic document root with  
wget [https://m.dev.testserver.online/mtc.js](https://m.dev.testserver.online/mtc.js)

**5) PHP Sessions in Redis**

Status: Running in production

Configure in the php.ini like this:

[Session]  
; Handler used to store/retrieve data.  
; [PHP: Runtime Configuration - Manual](http://php.net/session.save-handler)  
session.save\_handler = redis  
session.save\_path = “tcp://127.0.0.1:6379?database=10”  
redis.session.locking\_enabled = 1  
redis.session.lock\_retries = -1  
redis.session.lock\_wait\_time = 10000

Check in Mautic under \<your\_mautic-domain\>/s/sysinfo under PHP info

Should look like this:

 ![Bildschirmfoto 2024-07-21 um 13.50.35](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/7/79d904f9f71f6e9016d43959ebe7e6498c866f94.png)

**6) Master/Slave Database Handling**

Status: Development / Needs testing for this version

Mautic supports Master/Slave Configurations. It’s already part of the source code:

See Source Code from Mautic 4:

 ![Bildschirmfoto 2024-07-21 um 14.05.06](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/3/33370550d960c04dfa2e7c4b5852ba46b18429ba.jpeg)

In the past (Mautic 2.15) I used this already.

I added a db\_host\_ro param to local.php to define a read only mysql slave.  
**I try to adapt the configuration for mautic 4 but could not test it.**

Important place this before trick 2) because both are changing the same config.

Anyways here is my code snippet for changing config\_override.php:

```auto
<?php 

// Read Only db cluster support.
// In future this may be best as a modification of the core config.php.
$dbHostRO = $container->hasParameter('mautic.db_host_ro') ? $container->getParameter('mautic.db_host_ro') : null;
if (!empty($dbHostRO)) {

    // Default from config.php
    $dbalSettings = [
        'driver' => '%mautic.db_driver%',
        'host' => '%mautic.db_host%',
        'port' => '%mautic.db_port%',
        'dbname' => '%mautic.db_name%',
        'user' => '%mautic.db_user%',
        'password' => '%mautic.db_password%',
        'charset' => 'utf8mb4',
        'default_table_options' => [
            'charset' => 'utf8mb4',
            'collate' => 'utf8mb4_unicode_ci',
            'row_format' => 'DYNAMIC',
        ],
        'types' => [
            'array' => \Mautic\CoreBundle\Doctrine\Type\ArrayType::class,
            'datetime' => \Mautic\CoreBundle\Doctrine\Type\UTCDateTimeType::class,
            'generated' => \Mautic\CoreBundle\Doctrine\Type\GeneratedType::class,
        ],
        // Prevent Doctrine from crapping out with "unsupported type" errors due to it examining all tables in the database and not just Mautic's
        'mapping_types' => [
            'enum' => 'string',
            'point' => 'string',
            'bit' => 'string',
        ],
        'server_version' => '%mautic.db_server_version%',
    ];

    // Add a single slave (which is a load balanced Aurora read-only cluster).
    $dbalSettings['keep_replica'] = true;
    $dbalSettings['slaves'] = [
        'slave1' => [
            'host' => $dbHostRO,
            'port' => '%mautic.db_port%',
            'dbname' => '%mautic.db_name%',
            'user' => '%mautic.db_user%',
            'password' => '%mautic.db_password%',
            'charset' => 'UTF8',
        ],
    ];
    
    // Default from config.php
    $container->loadFromExtension('doctrine', [
        'dbal' => $dbalSettings,
        'orm' => [
            'auto_generate_proxy_classes' => '%kernel.debug%',
            'auto_mapping' => true,
            'mappings' => $bundleMetadataBuilder->getOrmConfig(),
            'dql' => [
                'string_functions' => [
                    'match' => \DoctrineExtensions\Query\Mysql\MatchAgainst::class,
                ],
            ],
        ],
    ]);
}

```

I learned this trick from the great DSMGroup:

> <https://github.com/TheDMSGroup/mautic-eb/blob/e4ba81abfa4b17ef52c43ad118d42e00f72f00f3/mautic_eb/app/config/config_prod.php#L64>

(btw: the repository also teaches me a lot of other mautic tricks. It’s gold)

[Next page](https://forum.mautic.org/t/configuring-memcache-or-redis-in-local-php/27267.md?page=2)
