Tagged: 

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #100020
    Torlock
    Guest

    Sorry for the separate thread, I can’t update the original anymore here: https://www.boldgrid.com/support/question/database-cluster/

    In 2.4.0 there was a fix for this issue: https://github.com/BoldGrid/w3-total-cache/pull/708

    However, after installing the update my read replica has yet to have a single connection in the last 2 hours which suggests it’s not working still.

    I can now see the DB Cluster settings in the WP backend which is a step in the right direction.

    Probably worth mentioning, the WP backend says, ‘Create db-cluster-config.php file with your database cluster configuration to enable it’ and other places online as well as the sample filename mention dbcluster-config.php (slightly different filename) – though I’ve tried under both names without luck. Can you confirm which it should be?

    My db-cluster-config.php/dbcluster-config.php:

    
    <?php
    
    global $w3tc_dbcluster_config;
    
    $w3tc_dbcluster_config = array(
    	/**
    	 * Persistent (bool)
    	 *
    	 * This determines whether to use mysql_connect or mysql_pconnect. The effects
    	 * of this setting may vary and should be carefully tested.
    	 * Default: false
    	 */
    	'persistent' => false,
    
    	/**
    	 * check_tcp_responsiveness
    	 *
    	 * Enables checking TCP responsiveness by fsockopen prior to mysql_connect or
    	 * mysql_pconnect. This was added because PHP's mysql functions do not provide
    	 * a variable timeout setting. Disabling it may improve average performance by
    	 * a very tiny margin but lose protection against connections failing slowly.
    	 * Default: true
    	 */
    	'check_tcp_responsiveness' => true,
    
    	/**
    	 * Default is to always (reads & writes) use the master db when user is in administration backend.
    	 * Set use_master_in_backend to false to disable this behavior.
    	 *
    	 * WARNING: if your cluster has any replication delays then when this is enabled, you may not see
    	 * any admin changes until the replication catches up with the change written to your master
    	 * server and will see old content/configuration until that point in time - You should test this
    	 * in your environment fully.
    	 */
    	'use_master_in_backend' => true,
    );
    
    	/** Configuration Functions **/
    
    	/**
    	 * database is an associative array with these parameters:
    	 * host             (required) Hostname with optional :port. Default port is 3306.
    	 * user             (required) MySQL user name.
    	 * password         (required) MySQL user password.
    	 * name             (required) MySQL database name.
    	 * read             (optional) Whether server is readable. Default is 1 (readable).
    	 *			    Also used to assign preference.
    	 * write            (optional) Whether server is writable. Default is 1 (writable).
    	 *                             Also used to assign preference in multi-master mode.
    	 * dataset          (optional) Name of dataset. Default is 'global'.
    	 * timeout          (optional) Seconds to wait for TCP responsiveness. Default is 0.2
    	 * connect_function (optional) connection function to use
    	 * zone             (optional) name of zone where server is located.
    	 *                             Used for web applications hosted on cluster
    	 *
    	 * Read & write
    	 * A database definition can include 'read' and 'write' parameters. These
    	 * operate as boolean switches but they are typically specified as integers.
    	 * They allow or disallow use of the database for reading or writing.
    	 *
    	 * A master database might be configured to allow reading and writing:
    	 *   'write' => true,
    	 *   'read'  => true,
    	 * while a slave would be allowed only to read:
    	 *   'write' => false,
    	 *   'read'  => true,
    	 *
    	 * It might be advantageous to disallow reading from the master, such as when
    	 * there are many slaves available and the master is very busy with writes.
    	 *   'write' => true,
    	 *   'read'  => false,
    	 *
    	 */
    
    /**
     * This adds the same server again, only this time it is configured as a slave.
     * The last three parameters are set to the defaults but are shown for clarity.
     */
    
    $w3tc_dbcluster_config = array(
    	'databases' => array(
    		'master' => array(
    			'host'     => DB_HOST,
    			'user'     => DB_USER,
    			'password' => DB_PASSWORD,
    			'name'     => DB_NAME
    		),
    		'slave' => array(
    			'host'     => 'redacted',
    			'user'     => DB_USER,
    			'password' => DB_PASSWORD,
    			'name'     => DB_NAME,
    			'write'    => false,
    			'read'     => true,
    			'timeout'  => 0.4,
    )));
    
    #100032
    Marko Vasiljevic
    Keymaster

    Hello Torlock,

    Thank you for reaching out.
    The drop-in should be – db-cluster-config.php

    Please manually delete the db.php and db-cluster-config.php. Go to W3 Total Cache and enable DB cluster.
    As mentioned before, you need to edit the db-cluster-config.php and once you are prompted to edit Database Cluster Configuration File, instead of using the entire example, use the following:

    <?php
    
    global $w3tc_dbcluster_config;
    
    $w3tc_dbcluster_config = array(
    	'databases' => array(
    		'master' => array(
    			'host'     => DB_HOST,
    			'user'     => DB_USER,
    			'password' => DB_PASSWORD,
    			'name'     => DB_NAME
    		),
    		'slave' => array(
    			'host'     => DB_HOST,
    			'user'     => DB_USER,
    			'password' => DB_PASSWORD,
    			'name'     => DB_NAME,
    			'write'    => false,
    			'read'     => true,
    			'timeout'  => 0.2
    		),
    	)
    );

    Once you finish and save the config file, you can inspect the source in backend and you will see the following W3TC HTML snippet:

    <!--
    Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/
    
    <strong>Database cluster enabled </strong>
    
    Served from: yourwebsite.com @ 2023-08-04 16:40:16 by W3 Total Cache
    -->

    Let me know if this helps!

Viewing 2 posts - 1 through 2 (of 2 total)
  • The topic ‘DB Cluster still doesn’t appear to be orking post 2.4.0 update’ is closed to new replies.