We are currently migrating our project to symfony2. The website uses multiple domains:

domain.com - main website

help.domain.com - faq

profile.domain.com - for user CP

and so on

To make it work my idea is to create directory 'sites' and for each subdomain create its own directory where it has framework files + vendor directory with symlinks to directories in root vendor/* (every dir except composer and autoload.php file).
So the structure looks something like this:

I needed to do it this way, because autoload has to be abit different for every domain (we store code that is shared between domains in vendor/Company, and code that is unique for each domain is stored in /src folder of domain directory).

The problem is that now i have to do "composer install" at each directory and it creates its own composer.lock and if i later update at any of the directories, the libs will be updated, but composer.lock files will not be synced, so it will just reinstall it each time.

Is there a better way to solve this problem ? (I thought of putting composer only at the root direcotry, but I didn't find a way to dump different autoload.php files for every domain).

1 Answer
1

You either have one project with a single set of dependencies or two projects with separate deps. Anything in between does not make sense. Seems like you want to go with the first option but have concerns about autoload performance.

The thing is that by default, autoloading will be slow anyways. So even if you had two separate autoload files including only the deps of the specific sub-project, it would probably still be quite slow.

What you really should do is dump a class map, which is basically an autoload file that maps all class names to the files they reside in. This keeps the stat calls down and is thus very efficient. And loading the entire class map in both sub-projects should not give you too much overhead either, especially if you have APC enabled.

You can dump the class map file by using this command:

$ composer dump-autoload --optimize

Now you should get increased autoloading performance.

TLDR: Use a single composer.json with class map autoloading, it is fast.

"It will create the file in vendor/composer/autoload_classmap.php. Just include that one instead of vendor/autoload.php." Shouldn't we still require vendor/autoload.php?
–
Halil ÖzgürFeb 22 '13 at 10:03

@HalilÖzgür You are right. Not sure if I made a mistake or if this changed in composer since back then. I'll update the answer.
–
igorwFeb 22 '13 at 13:46