Jump to content

moving from single site to multi-sites with own dbs @ one core


valan
 Share

Recommended Posts

I'm developing relatively big site with a number of weakly connected web-services. By "weakly connected" I mean that they share same users and some common catalog but the rest (and bigger part) is not shared (service-specific catalogs, languages, etc).

As site becomes too big and complicated I think to move these weakly connected web-services to their own sites, e.g. one PW core but several sites with their own dbs. Users as well as shared catalog remain at "main" site, being maintainable via PW admin.

Before this move I'd like to consult with you guys. Specifically - would this code work at "web-service" sites?

$temp = $wire; // temporary save "current site $wire"

include("../../../site-main/index.php"); // bootstrap PW main domain $wire. Main domain and Service domain sites are in one directory, ../../../ path prefix used to navigate from current templates directory to common parent folder of all sites. 

$mainWire = $wire; // set variable to be used for access/manipulations at main site
$wire     = $temp; // set $wire back to "current site $wire"

$user1 = $mainWire->users->get('email=email@example.com')->first(); // returns User instance from main site / main domain db

$user2 = $wire->users->get('email=email@example.com')->first(); // returns User instance from current site / current domain db

I am aware of http://modules.processwire.com/modules/service-pages/ but due to security&performance reasons I think that if "hardcode" above works then it should be a better choice.

P.S. wire/index.config.php

function ProcessWireHostSiteConfig() {
    return array(
             'maindomain.com'     => 'site-main',
             'www.maindomain.com' => 'site-main',

             'service1.com'       => 'site-service1',
             'www.service1.com'   => 'site-service1',

             'service2.com'       => 'site-service2',
             'www.service2.com'   => 'site-service2'

             // etc other services
            );
}
 
Link to comment
Share on other sites

I don't think that you could get two instances of ProcessWire running from the same PHP script. Perhaps that's something we should work towards for the future (and we really aren't far from it), but currently the convenience and simplicity of being able to use functions like wire('api var'); among others, takes precedence over true isolation of the ProcessWire instance. While I've not tried it, I'm pretty sure this would prevent you from having more than one PW instance operating from the same PHP script. You would need your multiple PW instances to use more traditional web service communication. 

  • Like 2
Link to comment
Share on other sites

Thanks, Ryan!

Unfortunately I'm not familiar with traditional web service communications but looks like I have to...

Running several instances in one script could be a great addition for entry-level coders who actually like PW and don't know (or don't want to know) how to dig sql dbs. Such functionality significantly reduces a need to know sql as now you can use PW in "external storage" scenarios. E.g. storing any shared catalogs in dedicated PW instances and have the same interface, api, maintainability through PW admin, etc.

By the way, I guess that new api variable should be called $wires :rolleyes:.

  • 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

×
×
  • Create New...