horst Posted July 24, 2020 Share Posted July 24, 2020 Hi all, I tried to run two instances of pw that resides in parallel directories of the same server. I've done like it was explained in a older blog post (around PW 3.0.32) and it throughs me a compile error, regardless if in web environment or on CLI. <?php namespace ProcessWire; if(!defined('PW_MASTER_PATH')) define('PW_MASTER_PATH', 'E:/laragon/www/pw1/'); // PW 3.0.162 if(!defined('PW_MASTER_HTTPURL')) define('PW_MASTER_HTTPURL', 'https://pw1.local/'); if(!defined('PW_SITE2_PATH')) define('PW_SITE2_PATH', 'E:/laragon/www/pw2/'); // PW 3.0.160 if(!defined('PW_SITE2_HTTPURL')) define('PW_SITE2_HTTPURL', 'https://pw2.local/'); // bootstrap ProcessWire master instance require_once(PW_MASTER_PATH . 'index.php'); // create a second instance $site = new ProcessWire(PW_SITE2_PATH, PW_SITE2_HTTPURL); // or: new ProcessWire(PW_SITE2_PATH); The error is: Compile Error: Cannot redeclare pages() (previously declared in E:\__PW-DISTRIS\wire-3.0.162\core\FunctionsAPI.php:63) (line 63 of E:\__PW-DISTRIS\wire-3.0.160\core\FunctionsAPI.php) So, is there a newer / other way nowadays to create a second instance? Link to comment Share on other sites More sharing options...
kongondo Posted July 24, 2020 Share Posted July 24, 2020 45 minutes ago, horst said: // bootstrap ProcessWire master instance require_once(PW_MASTER_PATH . 'index.php'); This is a curious line. Why do you need this? Or are you ONLY using it if on CLI? Link to comment Share on other sites More sharing options...
kongondo Posted July 24, 2020 Share Posted July 24, 2020 47 minutes ago, horst said: So, is there a newer / other way nowadays to create a second instance? Nothing newer. I use multi-instance recently and it worked fine. 1 Link to comment Share on other sites More sharing options...
LostKobrakai Posted July 24, 2020 Share Posted July 24, 2020 You might need to disable the new(ish) function api. These are global functions and as the error shows you may not redefine those. 2 Link to comment Share on other sites More sharing options...
horst Posted July 24, 2020 Author Share Posted July 24, 2020 In this post (https://processwire.com/docs/start/api-access/) Ryan says Quote Other API access methods Using the API with multiple ProcessWire instances Technically you can boot multiple different instances of ProcessWire. In a multi-instance environment there may be some ambiguity about what instance API functions and variables are referring to. So, this has made me thinking it should be. Also I tried setting it on the fly to false before creating the second instance. But I had not verified that it was definetly disabled. Now after writing it into all site/config.php files, the error is gone and I get multiple instances. But I encountered a new weird thing: I loaded three instances with the PW versions 3.162 + 3.0.160 + 3.0.155. But when executing this code, every instance shows me the 162 !! ?? ? // bootstrap ProcessWire master instance require_once(PW_MASTER_PATH . 'index.php'); mvd($wire->getInstanceNum() .' # '. $wire->config->version); // echo instance and version of the master (expected: 3.0.162) $wire = new \ProcessWire\ProcessWire(PW_MASTER_PATH); mvd($wire->getInstanceNum() .' # '. $wire->config->version); // echo instance and version of the new created instance from master (expected: 3.0.162) $site2 = new ProcessWire(PW_SITE2_PATH, PW_SITE2_HTTPURL); mvd($site2->getInstanceNum() .' # '. $site2->config->version); // echo instance and version of site2 (expected: 3.0.160) $site3 = new ProcessWire(PW_SITE3_PATH, PW_SITE3_HTTPURL); mvd($site3->getInstanceNum() .' # '. $site3->config->version); // echo instance and version of site3 (expected: 3.0.155) die('RIP'); 1 Link to comment Share on other sites More sharing options...
pwfans Posted July 30, 2020 Share Posted July 30, 2020 I'm using 2 multi instance, both same version (3.0.148) with this state at config.php $config->useFunctionsAPI = false; Link to comment Share on other sites More sharing options...
kongondo Posted July 30, 2020 Share Posted July 30, 2020 1 hour ago, pwfans said: I'm using 2 multi instance, both same version (3.0.148) with this state at config.php $config->useFunctionsAPI = false; Yes, thanks. @horst found out the same and wrote this tutorial ? 2 Link to comment Share on other sites More sharing options...
pwfans Posted August 3, 2020 Share Posted August 3, 2020 @kongondo Thanks a lot ! just knew functions API can be enabled by this way ? Link to comment Share on other sites More sharing options...
modifiedcontent Posted April 27, 2022 Share Posted April 27, 2022 My multiple instances (?) broke in upgrade somewhere between v3.0.169 and 3.0.198 dev. Did something change? What is currently the way to use this? I have to go back to basics and try to rebuild it. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now