Skip to content

add a cookbook entry about how to have multiple kernels #997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lsmith77 opened this issue Jan 17, 2012 · 16 comments
Closed

add a cookbook entry about how to have multiple kernels #997

lsmith77 opened this issue Jan 17, 2012 · 16 comments
Labels
actionable Clear and specific issues ready for anyone to take them. hasPR A Pull Request has already been submitted for this issue.

Comments

@lsmith77
Copy link
Contributor

this could be based on https://github.com/liip/sf2debpkg

@weaverryan
Copy link
Member

I think if we can find a decent use case (and then strongly warn people that they probably don't need this), then I think it's a great idea. I want to make sure that even if we teach people how, we make sure they ask whether or not they actually need this :).

@wouterj
Copy link
Member

wouterj commented Mar 30, 2013

when this is documented, we can link to it from reference/configuration/kernel

@mpdude
Copy link
Contributor

mpdude commented May 14, 2013

You think #2465 solved this?

If not, what do you think is missing?

@wouterj
Copy link
Member

wouterj commented May 14, 2013

I like to have some stronger warning that you properbly do not need this.

And I like to have some interlinking from reference/configuration/kernel#kernel.name

@mpdude
Copy link
Contributor

mpdude commented May 14, 2013

As to kernel.name, by coincidence I came across that today. I did not really see what it is important for and how it should be best chosen. If you can help me to understand that I'd be glad to improve the docs.

Update: Same for the kernel.root_dir. What should that best point to and is it important for anything besides being a base for the cache and logs dir?

@wouterj
Copy link
Member

wouterj commented May 15, 2013

Well, first of all, I maened we cannlink to this article from the kernle.name setting description.

The kernel name is used when generating the classes for the container or routing. The default value will work in most of the cases and you won't worry about it.

The kernel.root_dir is the only path that is known by symfony. All included configuration and other things are based on it. This one usually don't need to be overriden too.

Please note some comment by stof:

The case where it is useful is having several kernels (in which case you still don't care about the values as long as they are different) but the default value should be still enough most of the time as the easiest way to achieve multiple kernels (i.e. without having to overwrite lots of stuff) is simply to duplicate the structure of the app folder in a different folder (the name of the kernel defaulting to the name of this folder)

That's something different than the cookbook article explains it:

When putting multiple Kernels into a single application, it might therefore make sense to add additional sub-directories, for example app/admin/AdminKernel.php and app/api/ApiKernel.php

@stof
Copy link
Member

stof commented May 16, 2013

@wouterj The issue with moving the structure of app in subfolder is that it requires changing the Assetic config for the path accessing the web folder whereas my solution keeps the same path

@cordoval
Copy link
Contributor

cordoval commented Jan 6, 2014

@weaverryan why would they don't strongly need this? I have been in places where we implemented this and also I got advised back long ago by merk about this too. Usually the use case is a front end with a quick rest api. If you can shed light please it would be great. Thanks man!

@weaverryan
Copy link
Member

@cordoval strongly warn people about not doing this until they have a good use case. An API versus a normal app seems like a good use-case.

@javiereguiluz
Copy link
Member

@kbond I've just read this comment that you made on Bundles, No Bundles and AppBundle in 10 Steps:

I thought multi-kernel projects were rare but after talking to some people in NY it is not as rare I thought... But, I wouldn't say it is common and it requires some advanced knowledge.

Could you please share with us some of those multi-kernel projects scenarios? This is something we want to document since a lot of time ago and we need someone to outline some basic ideas for the cookbook. Thanks in advance for your help!

@weaverryan
Copy link
Member

And I had the same experience as @kbond - I was surprised (at least by conference-goers) by how many people had multiple kernels. @meandmymonkey also mentioned some use-cases beyond an API backend and web frontend, like a kernel just for commands (the advantage being the kernel is a bit slimmer, which is not important for many, but important if you're squeezing performance).

I still think that most people don't need this, but it's definitely a legitimate use-case, and this entry would really be quite simple to write. @javiereguiluz thanks for re-pinging :).

@kbond
Copy link
Member

kbond commented Dec 12, 2014

@javiereguiluz the only scenarios I can recall are the ones Ryan mentioned. I think there was a comment from the audience during one if the talks (maybe Fabien's) about a multi Kernel environment but I can't remember their scenario.

@wouterj
Copy link
Member

wouterj commented Dec 12, 2014

Recently, I had a very slow dev environment due to some 3th party bundles with lots of templates. It made the twig cacher very slow and with that, also each request in dev.
Since I needed the bundles only on some routes, I did create a kernel just for those bundles. This way, most of the site had a quick dev environment. In production, I just used the full kernel (with all bundles).

I don't know if this is a good practice though...

@stof
Copy link
Member

stof commented Jan 4, 2015

Having a different kernel in prod and dev looks really weird to me.

@kbond the common use case for multiple kernel IMO is having an API and a website in the same project. The API can use a separate kernel, allowing to avoid loading a bunch of bundles it does not need (related to the website stuff) and loading other bundles which should affect only the API (FOSRestBundle for instance)

@weaverryan
Copy link
Member

+1 for the example with a "website" (frontend) and an API. It works especially well since you can show how some API-related bundles don't need to be enabled for the "website" kernel. I don't think this entry needs to be huge - just highlight some directory structure stuff, show how you have different bundles registered (but you use some bundles on both), and why you would use this approach.

@javiereguiluz javiereguiluz added the hasPR A Pull Request has already been submitted for this issue. label Oct 12, 2016
weaverryan added a commit that referenced this issue Dec 15, 2016
…rnels (javiereguiluz)

This PR was merged into the 2.7 branch.

Discussion
----------

Added a new article about applications with multiple kernels

This fixes #997 (opened in January 2012 !!!).

---

1) I don't know which is the best location for this article (probably not `request/`)

2) When merging up, in the 2.8 branch the following must be added:

At the end of `Step 2)`, add this:

``` rst
In order to make this class available in the front controller, don't forget to
add it to the ``classmap`` configuration of the ``composer.json`` file:

.. code-block:: json

    {
        "autoload": {
            "psr-4": { "": "src/" },
            "classmap": ["app/AppKernel.php", "app/ApiKernel.php"]
        },
        ...
    }
```

At the end of the article, add this:

``` rst
.. tip:

    Symfony 2.8 introduced a `new micro kernel`_ PHP trait that simplifies the
    creation of kernels. You can even define them in a single PHP file.

.. _`new micro kernel`: http://symfony.com/blog/new-in-symfony-2-8-symfony-as-a-microframework

```

Commits
-------

bc3618d Made a bunch of fixes recommended by Ryan
2613810 Added a note about rendering templates from different kernels
e403fd8 Added a new section about running commands under a different kernel
af4ff18 Added a new use case related to micro-services
2c5aeb1 Removed a use case
097a73d Reworded the use cases section
5c8ed87 Fixed typo
d45e1f4 Fixed an example code
a23d82d Fixed another syntax issue
21329ec Fixed some syntax issues
7cb2aa1 Added a new article about applications with multiple kernels
@weaverryan
Copy link
Member

Boom!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actionable Clear and specific issues ready for anyone to take them. hasPR A Pull Request has already been submitted for this issue.
Projects
None yet
Development

No branches or pull requests

8 participants