Jump to content
horst

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

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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

  • Like 1

Share this post


Link to post
Share on other sites

You might need to disable the new(ish) function api. These are global functions and as the error shows you may not redefine those.

  • Like 2

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

I'm using 2 multi instance, both same version (3.0.148) with this state at config.php 

$config->useFunctionsAPI = false;

 

Share this post


Link to post
Share on other sites
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 😄 

 

 

  • Like 2

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...