From 7f91cad42f99b9e2a6a528a1c1bd592fbe8d0546 Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Mon, 19 Apr 2021 09:48:04 -0400 Subject: [PATCH] Add support for multiple randomly selected DB readers (config.php file updates) --- wire/config.php | 8 ++++++++ wire/core/Modules.php | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/wire/config.php b/wire/config.php index 05fac1b8..1ff57ec7 100644 --- a/wire/config.php +++ b/wire/config.php @@ -1229,6 +1229,14 @@ $config->dbStripMB4 = false; * if($config->requestMethod('GET') && !$config->requestPath($skipPaths)) { * $config->dbReader = [ 'host' => 'readonly.mydb.domain.com' ]; * } + * + * // to have PW randomly select from multiple DB readers, nest the arrays (3.0.176+) + * // if a connection fails, PW will try another randomly till it finds one that works + * $config->dbReader = [ + * [ 'host' => 'mydb1.domain.com' ], + * [ 'host' => 'mydb2.domain.com' ], + * [ 'host' => 'mydb3.domain.com' ], + * ]; * ~~~~~ * * @var array diff --git a/wire/core/Modules.php b/wire/core/Modules.php index 910ba214..cef89875 100644 --- a/wire/core/Modules.php +++ b/wire/core/Modules.php @@ -2829,6 +2829,9 @@ class Modules extends WireArray { * - `useNavJSON` (bool): whether the Process module provides JSON navigation * - `permissionMethod` (string|callable): method to call to determine permission * - `page` (array): definition of page to create for Process module + * + * On error, an `error` index in returned array contains error message. You can also identify errors + * such as a non-existing module by the returned module info having an `id` index of `0` * * ~~~~~ * // example of getting module info @@ -2849,7 +2852,9 @@ class Modules extends WireArray { * - `verbose` (bool): Makes the info also include verbose properties, which are otherwise blank. (default=false) * - `minify` (bool): Remove non-applicable and properties that match defaults? (default=false, or true when getting `all`) * - `noCache` (bool): prevents use of cache to retrieve the module info. (default=false) - * @return array Associative array of module information + * @return array Associative array of module information. + * - On error, an `error` index is also populated with an error message. + * - When requesting a module that does not exist its `id` value will be `0` and its `name` will be blank. * @see Modules::getModuleInfoVerbose() * @todo move all getModuleInfo methods to their own ModuleInfo class and break this method down further. *