Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+5 votes
650 views
in Q2A Core by

I found some configuration options in qa-confing.php file to optimize Q2A site performance. I understand little how it works but don't know how to implement properly it on the Q2A site.

1. QA_CACHE_DIRECTORY

I have configured my qa-cache folder in the qa-confing.php file like this:

define('QA_CACHE_DIRECTORY', '/home/u310886959/domains/mydomain.com/public_html/qa-cache');

And it is working for me when I am enabling it from Admin/Caching - (FileSystem), I show the comment there "For maximum security, it's STRONGLY recommended to place the folder outside of the webroot (so they can never be accessed via a web browser)".

Question: Where should I put my qa-cache folder? (look my path above)


2. QA_COOKIE_DOMAIN

Many times I get speed improvement tips from page speed testing tools like "GTmetrix, Pingdom" to serve static resources from a cookie-free domain.

Question 1: Can I configure the "QA_COOKIE_DOMAIN" option to archive what speed testing tools asking to do? If "Yes",

Question 2: How to set up a cookie-free domain for the Q2A site?

I know if I want to set up a cookie-free domain then I have to create a subdomain like static.mydomain.com and then I have to put my static resources there.

Question 3: Which Q2A installation folders are static and I have to move them from mydomain.com to static.mydomain.com and how to link their path to work Q2A site?

I am currently using Cloudflare CDN. Is there anything to change with Cloudflare after moving static resources to static.mydomain.com?


3. QA_OPTIMIZE_DISTANT_DB

My site is currently on shared hosting and I think my Q2A installation & database are running on the same server. There is only 2 thing to configure, set it to "true" or "false".

Question 1: Should I set it to "true"?

Question 2: How it works?


A very long question asked but I know it will definitely help many Q2A users to optimize their site. (If properly set up)

Q2A version: 1.8.5
by
+4
I suggest users to always describe the issues in detail so the chances are higher to get proper solutions. :)

1 Answer

+3 votes
by
edited by

1. QA_CACHE_DIRECTORY

The path can basically be whatever you like, as long as it's outside your webroot, but the FHS suggests /var/cache for cached application data. So, something like this should do:
define('QA_CACHE_DIRECTORY', '/var/cache/q2a/');

Note that this assumes you have root access to the server. Should that not be the case you need to pick a location where you have write access (but still outside the web root directory), for instance

define('QA_CACHE_DIRECTORY', '/home/u310886959/q2a-cache/');

If you're running several sites you should use separate caches per site, e.g.

define('QA_CACHE_DIRECTORY', '/home/u310886959/q2a-cache/example.com/');

3. QA_OPTIMIZE_DISTANT_DB

From the documentation:

Question2Answer is engineered to minimize the number of MySQL queries used per page. This allows you to separate your database and web servers without suffering too much from latency. The downside is that the resulting queries can be quite complex. If your database and web servers are running on the same box, latency is not an issue, so set QA_OPTIMIZE_LOCAL_DB to true and QA_OPTIMIZE_DISTANT_DB to false in qa-config.php. This will uses many simple MySQL queries instead of fewer complex ones.

However, the part about the the QA_OPTIMIZE_LOCAL_DB setting is apparently outdated according to the comments in the config:

The option QA_OPTIMIZE_LOCAL_DB is no longer used, since QA_OPTIMIZE_DISTANT_DB covers our uses.

If the database and application are running on the same server use the default setting

define('QA_OPTIMIZE_DISTANT_DB', false);

That will increase the number of queries against the database, but since no remote connection is involved the cost for that is cheap. For a remote database you want to reduce the number of connections to improve performance, because network traffic is expensive (compared to local connections).

...