Symfony2 and multiple applications

Showing 1-28 of 28 messages
Symfony2 and multiple applications Robert Knutsson 6/23/11 12:52 AM
Hi

I needed two applications in my symfony2 project and read the manual
(http://symfony.com/doc/2.0/cookbook/symfony1.html) where
the concept of applications in symfony2 was explained.

Although the manual is very vague on how to implement two
applications, and there is no "best-practice" to be found on the
subject.

My issue is that I wanna keep duplicated code to a minimum, and I need
some input on how to not duplicate "bootstrap.php.cache",
"autoload.php" and "console".

Could you recommend me some best practices when it comes to multiple
applications in symfony2 or share your experiences?

Cheers,
Robert
Re: [symfony-devs] Symfony2 and multiple applications Fabien Potencier 6/23/11 3:36 AM

Short answer: You never need more than one application in Symfony2.

Can you explain why you want to create two applications?

Fabien

> Cheers,
> Robert
>

Re: Symfony2 and multiple applications Robert Knutsson 6/23/11 3:51 AM
As it stands now, I'm developing two services, deployed on the same
server, sharing the same database. These services each have different
hostnames.
I have 3 bundles, one for each service and a shared bundle with the
entities.

If I have one application i have to seperate the services with routes,
and that is not possible. I have to seperate them by hostname. And
that is why I chose to create two application.

If there is any way to avoid this then I'm happy to oblige, but at the
moment this is the situation.

On 23 Juni, 12:36, Fabien Potencier <fabien.potenc...@symfony-
Re: [symfony-devs] Symfony2 and multiple applications Lukas Kahwe Smith 6/23/11 3:58 AM

We have doen projects with multiple applications in one git repo in projects. The idea being that for development its easier to have them all in one repo, but for deploying we want to keep them separate. For example one server with the admin interface, another one with the frontend, another one with the API. this lets us scale things separately. it also makes it easier to control the impact of misconfigurations etc.

We have defined a dir structure for this and also developed tools to handle packaging the applications into separate .deb files:
https://github.com/liip/sf2debpkg

regards,
Lukas Kahwe Smith
m...@pooteeweet.org

Re: [symfony-devs] Symfony2 and multiple applications cordoval 6/23/11 5:03 AM
Oh wow did not know about this lsmith
This looks like the debianizebundle or similar bundles I have seen around.
Thanks for sharing... not very popular but interesting.

> --
> If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com
>
> You received this message because you are subscribed to the Google
> Groups "symfony developers" group.
> To post to this group, send email to symfon...@googlegroups.com
> To unsubscribe from this group, send email to
> symfony-devs...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/symfony-devs?hl=en
>

Re: Symfony2 and multiple applications Venzon 6/23/11 6:37 AM
I am using 2 applications in my sf2 project. One is holding frontend
configuration and second is for backend configuration.
We decided to use 2 applications because both configs are way
different but use same databases, same entities and some common
bundles.
When we separated backend and frontend applications then we have only
whats really needed in project container.

On 23 Cze, 12:36, Fabien Potencier <fabien.potenc...@symfony-
Re: Symfony2 and multiple applications Cédric Lahouste 6/23/11 12:46 PM
I don't understand why we need only one application. Could you explain
more about it?

If there are bundles, they could be used by more than one project (and
more in local dev, I guess).

In local, I am using this structure:
app/console + web/app: symfony-standard
app1/console + web/app1 : project 1 => www.project1.local
app2/console + web/app2 : project 2 => www.project2.local
app3/console + web/app3 : project 3 => www.project3.local
Using this structure, vendors & own bundles are totally shared.

Regards,

On 23 juin, 12:36, Fabien Potencier <fabien.potenc...@symfony-
unk...@googlegroups.com 6/23/11 4:52 PM <This message has been deleted.>
Re: [symfony-devs] Re: Symfony2 and multiple applications Oscar B. 6/24/11 10:55 AM
You can setup your shared code on 1 git repo. When updating, just pull from the repo to every app dir ?

If you were developing an app with your bare hands (no Symfony, no Doctrine, no Routing component only your own implementation) 
how would you solve this same issue? Is there any other PHP framework able to do it?

Regard!

2011/6/23 Cédric Lahouste <cedric....@gmail.com>
--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to symfon...@googlegroups.com
To unsubscribe from this group, send email to
symfony-devs...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Re: Symfony2 and multiple applications Ilmer BV 6/27/11 6:51 AM
I think a many people use a fontend/backend structure. I couldn't find the best practice for this in Symfony2..
 
Is there a best practice if you want the frontend and backend in the same applications? Ideally you have one bundle with the business logic, backend and frontend code.
 
Regards,
Re: Symfony2 and multiple applications Nicolas 6/26/11 4:27 PM
Why not create two environnement each with special routes, and use
htaccess rewrite rules  to direct to the good app_[env].php?
Re: [symfony-devs] Re: Symfony2 and multiple applications Lukas Kahwe Smith 6/29/11 7:15 AM

On 27.06.2011, at 01:27, Nicolas wrote:

> Why not create two environnement each with special routes, and use
> htaccess rewrite rules  to direct to the good app_[env].php?


i think that would be perverting the normal use case for env's. i think you should have separate kernel if you want separate apps.

regards,
Lukas Kahwe Smith
m...@pooteeweet.org

Re: [symfony-devs] Re: Symfony2 and multiple applications Lukas Kahwe Smith 6/29/11 7:23 AM

On 27.06.2011, at 15:51, in...@ilmer.nl wrote:

> I think a many people use a fontend/backend structure. I couldn't find the best practice for this in Symfony2..
>
> Is there a best practice if you want the frontend and backend in the same applications? Ideally you have one bundle with the business logic, backend and frontend code.

the best practice was explained in this thread already:
simply create as many frontend controller + kernel's as you need

however the key question when putting multiple kernels into one repo is how many custom bundles are shared. if the answer is zero or very few, then i would recommend to use separate repo's for your applications and another repo for each shared bundle.

we have a project where lots of entities are shared across the admin, frontend and api kernels so they all sit in one repo for convenience.
in another project we have a REST api between the backend and frontend so in the end we only had custom bundle that is shared that we simply put in another repo to easily share it between the two applications.

regards,
Lukas Kahwe Smith
m...@pooteeweet.org

Re: Symfony2 and multiple applications Ilmer BV 6/29/11 7:24 AM
But seperate apps does also mean duplicate business logic code? The
frontend/backend can share a lot of helper functions and business
logic.

regards,

Niels Ilmer
Re: [symfony-devs] Re: Symfony2 and multiple applications Christophe COEVOET 6/29/11 7:27 AM
Le 29/06/2011 16:24, in...@ilmer.nl a �crit :

> But seperate apps does also mean duplicate business logic code? The
> frontend/backend can share a lot of helper functions and business
> logic.
>
> regards,
>
> Niels Ilmer
Simply put this shared logic in a separate bundle used in both apps.

--
Christophe | Stof

Re: [symfony-devs] Re: Symfony2 and multiple applications Thomas Lundquist 6/29/11 11:19 PM
On Wed, Jun 29, 2011 at 07:24:42AM -0700, in...@ilmer.nl wrote:
> But seperate apps does also mean duplicate business logic code?

The business logic is still in one or more bundles and the most app specific
can be in it's own bundle and only be used by one of the apps.

> The frontend/backend can share a lot of helper functions and business
> logic.

Absolutely and that is also the reason at least I would like to have the
apps/<appname>/ from Sf1 back instead of just app/

Two apps can also share the exact same code but may just use two different
DBs and then using the same source base but just different apps/<foo>/
directories with the configuration in it.

I am very in favour of putting this functionality back in and so far I have
not seen any good alternatives come up.


Thomas.

Re: [symfony-devs] Re: Symfony2 and multiple applications Lukas Kahwe Smith 6/29/11 11:26 PM


yes this approach works fine and we are using it in production.
again its documented on here https://github.com/liip/sf2debpkg

regards,
Lukas Kahwe Smith
m...@pooteeweet.org

Re: Symfony2 and multiple applications Jesse Greathosuse 6/30/11 6:00 AM
Hi,

I have a theory that there is a simple way to do this, however I have
never tried it so please bare with me.

In Symfony2 there is a variable used called $_SERVER['KERNEL_DIR'];
the reason I know its there is because I set it in my bundle unit test
boot strap to make sure the kernel sets up correctly in test cases
which require the kernel.

My theory is that you could set up different app.php files in your web
folder and set the $_SERVER['KERNEL_DIR'] in the app.php file

For instance if you have a sight called cats.com and another site
called dogs.com and they both used the same symfony base code but
different apps you could create one app folder and call it cats and
another app folder called dogs

Then in your .htaccess you could do something where you point all
traffic to cats.com at app_cats.php and all dogs.com traffic at
app_dogs.php

Then in your app_cats.php it would be like this:

<?php

$_SERVER['KERNEL_DIR']  =  __DIR__.'/../cats;

require_once $_SERVER['KERNEL_DIR'] .'/bootstrap.php.cache';
require_once $_SERVER['KERNEL_DIR'] .'/AppKernel.php';

use Symfony\Component\HttpFoundation\Request;

$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
$kernel->handle(Request::createFromGlobals())->send();

You'd probably have to make a similar change in your console script
but I think this would work. Please let me know if it does.
Re: [symfony-devs] Re: Symfony2 and multiple applications Lukas Kahwe Smith 7/4/11 1:06 AM


i guess there is another key question and that is who develops the given application and what is its upgrade cycle going to be.
for example if you have one team doing the frontend and another the backend it might be better to keep them split in different repos.

another point is when you want to upgrade dependencies. you might prefer not to have to update everything in one go. where again it would be nicer at times to have things in different repos.

regards,
Lukas Kahwe Smith
m...@pooteeweet.org

Re: Symfony2 and multiple applications Michael Piecko 7/9/11 4:19 AM
To bring this up again, i think this is the best multi app structure for a project (@Cédric Lahouste). The main reason i use this is because of APC. This way common php files like inside vendors/* or src/*etc. are only compiled once in APC memory, and not for each directory (project). Having 2 or more projects, each in a different folder will waste more APC memory for common files, like the whole Symfony2 framework.

As Fabien said, most of the time you won't need more than one app in a project. If you need a "backend", you can always route anything after "www.domain.com/backend" to a specific bundle and handle it there (while having access to all other bundles).

But if you (like me) prefer a clean separation (different cache & log dirs, different set of shared bundles etc.) then this approach is great. Almost all console commands have an option for a different app path. You can for example use "backoffice/console assets:install web/backoffice" to install all assets in the right place.

The only catch i found so far is the use of "vendors.php" and "build_bootstrap.php", where the "app" path is hardcoded. So this multi app functionality is possible, but not promoted like in symfony 1.

Michael
Re: [symfony-devs] Symfony2 and multiple applications Benjamin Meynell 1/19/12 7:55 PM
Short answer: You never need more than one application in Symfony2.

What's the long answer?
Re: [symfony-devs] Symfony2 and multiple applications Константин 2/14/12 3:39 AM
For example we have one site with multiple domains.

site.com // en
site.ru // ru

There is some hostname-related configuration (session domain cookie, security remember me cookie, session dfault locale) wich different in hostnames. And when container compiles it contains embedded/resolved parameters for only one hostname. So there is 2 possible sollutions:

1. use multiple apps
2. override some methods like getCacheDir in Kernel and resolve cache path
Re: [symfony-devs] Symfony2 and multiple applications weaverryan 2/14/12 8:16 AM
Hi there!

Another alternative is to have a service that figures out what your current "domain" is. You can then use a little trick created by OpenSky to make any parameter dynamic, which could be controlled by that service (https://github.com/opensky/OpenSkyRuntimeConfigBundle). The approach seems a little strange, but having runtime configs gives you the flexibility you need and seems less dramatic than multiple applications or cache directories.

There might be a better way, but just some thoughts!

Cheers!

Ryan Weaver
US Office Head & Trainer - KnpLabs - Nashville, TN
http://www.knplabs.com
http://www.thatsquality.com
Twitter: @weaverryan


2012/2/14 Константин <molod...@gmail.com>

--
If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com
 
You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to symfon...@googlegroups.com
To unsubscribe from this group, send email to
symfony-devs...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Re: [symfony-devs] Symfony2 and multiple applications Константин 3/14/12 3:31 PM
Thank you for advie.
It Looks like good sollution, but there are some problems on integration
https://github.com/opensky/OpenSkyRuntimeConfigBundle/issues/6


вторник, 14 февраля 2012 г. 18:16:36 UTC+2 пользователь weaverryan написал:
Re: [symfony-devs] Symfony2 and multiple applications Joshua Nankin 7/10/12 4:54 PM
I have the same problem, where I want multiple different "applications", that act differently and look differently, but really all have the same underlying business logic and require access to the same data stores.  Each application comes in on a different subdomain or domain name.  Here's how I'm solving it:
  • use .htaccess rules or webserver configuration to point domain names to specific front controllers (app1/app.php, app2/app.php)
  • create application specific configuration directories in app/config (app/config/app1/config.yml, app/config/app1/config_dev.yml)
  • At this point, you can override routing rules for each specific application by specifying a tailored routing.yml
Although people are saying they miss the Symfony1 application structure, this actually is a step up, as you can actually change routing and parameters much easier with the current setup, where as before you only really had one routing table you could work with.
Re: [symfony-devs] Symfony2 and multiple applications Joshua Nankin 7/10/12 5:03 PM
By the way, you do have to do some AppKernel tweaking to get it to understand the concept of an 'application', but really its just about changing the contructor to accept an application name, and then changing registerContainerConfiguration to load the correct configuration file.
Re: [symfony-devs] Symfony2 and multiple applications Lukas Kahwe Smith 7/10/12 10:42 PM

On Jul 11, 2012, at 3:03 AM, Joshua Nankin wrote:

> By the way, you do have to do some AppKernel tweaking to get it to understand the concept of an 'application', but really its just about changing the contructor to accept an application name, and then changing registerContainerConfiguration to load the correct configuration file.
>
> On Tuesday, July 10, 2012 6:54:24 PM UTC-5, Joshua Nankin wrote:
> I have the same problem, where I want multiple different "applications", that act differently and look differently, but really all have the same underlying business logic and require access to the same data stores.  Each application comes in on a different subdomain or domain name.  Here's how I'm solving it:
>         ∙ use .htaccess rules or webserver configuration to point domain names to specific front controllers (app1/app.php, app2/app.php)
>         ∙ create application specific configuration directories in app/config (app/config/app1/config.yml, app/config/app1/config_dev.yml)
>         ∙ At this point, you can override routing rules for each specific application by specifying a tailored routing.yml
> Although people are saying they miss the Symfony1 application structure, this actually is a step up, as you can actually change routing and parameters much easier with the current setup, where as before you only really had one routing table you could work with.
>
> On Wednesday, March 14, 2012 5:31:34 PM UTC-5, Константин wrote:
> Thank you for advie.
> It Looks like good sollution, but there are some problems on integration
> https://github.com/opensky/OpenSkyRuntimeConfigBundle/issues/6
>
>
> вторник, 14 февраля 2012 г. 18:16:36 UTC+2 пользователь weaverryan написал:
> Hi there!
>
> Another alternative is to have a service that figures out what your current "domain" is. You can then use a little trick created by OpenSky to make any parameter dynamic, which could be controlled by that service (https://github.com/opensky/OpenSkyRuntimeConfigBundle). The approach seems a little strange, but having runtime configs gives you the flexibility you need and seems less dramatic than multiple applications or cache directories.
>
> There might be a better way, but just some thoughts!
>
> Cheers!
>
> Ryan Weaver
> US Office Head & Trainer - KnpLabs - Nashville, TN
> http://www.knplabs.com
> http://www.thatsquality.com
> Twitter: @weaverryan
>
>
> 2012/2/14 Константин <molod...@gmail.com>
> For example we have one site with multiple domains.
>
> site.com // en
> site.ru // ru
>
> There is some hostname-related configuration (session domain cookie, security remember me cookie, session dfault locale) wich different in hostnames. And when container compiles it contains embedded/resolved parameters for only one hostname. So there is 2 possible sollutions:
>
> 1. use multiple apps
> 2. override some methods like getCacheDir in Kernel and resolve cache path

indeed .. we are using multiple kernels per application in many apps to be able to deploy parts of the application (like the main/mobile/admin/dbmigrations etc) to independent VM's

this is described in detail in our old debian generation tool chain
https://github.com/liip/sf2debpkg#application-structure

regards,
Lukas Kahwe Smith
m...@pooteeweet.org

PS: If you are interested in the new debian + RPM toolchain check out https://github.com/liip/packaging

Re: [symfony-devs] Symfony2 and multiple applications Daniel Gonzalez 7/10/12 11:53 PM
When i have multiple aplications i solve the problem just like that:

// app.php

use Symfony\Component\HttpFoundation\Request;

if (@$_SERVER['HTTP_HOST'] == 'admin.midomain.com') {
    $kernel = new AppKernel('admin', true);
} else {
    $kernel = new AppKernel('frontend', false);
}
$kernel->loadClassCache();
$kernel->handle(Request::createFromGlobals())->send();
> --
> If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com
>
> You received this message because you are subscribed to the Google
> Groups "symfony developers" group.
> To post to this group, send email to symfon...@googlegroups.com
> To unsubscribe from this group, send email to
> symfony-devs...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/symfony-devs?hl=en



--
-------------------------------------------------------------------------------------
Daniel González Cerviño
Open Source Developer http://desarrolla2.com
Tel (+34) 653 96 50 48
Mail daniel....@freelancemadrid.es
Twiter: http://twitter.com/desarrolla2
Linkedin: http://es.linkedin.com/in/danielgonzalezcervino
-------------------------------------------------------------------------------------
More topics »