Jump to content

What is the actual way to start multiple instances? I get compile error


horst
 Share

Recommended Posts

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

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');

image.png.169102b7445f81a727190144a943d573.png

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...