Skip to content

Allow specifying the location of auto-generated preload file #39061

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
yellow1912 opened this issue Nov 12, 2020 · 7 comments
Closed

Allow specifying the location of auto-generated preload file #39061

yellow1912 opened this issue Nov 12, 2020 · 7 comments

Comments

@yellow1912
Copy link

yellow1912 commented Nov 12, 2020

Description

We use Symfony to power hundreds of websites. Each website has its own database, but they share exactly the same code base (same vendor and app folder). The only difference is the local folder where we may setup different locales etc.

Right now, the preload file is generated and put in each website cache folder, we can not set preload config file.

Example

Ideally, I think it can be like this:

opcache.preload=/path/to/shared/var/cache/prod/App_KernelProdContainer.preload.php

(the tricky thing here is that we cannot share cache folder, each site has different template files for example so they have their own twig cache I think. Some other parameters can be different as well so ideally we only share the preload)

My current preload.php (which looks exactly the same for each site) looks like this:

<?php

// This file has been auto-generated by the Symfony Dependency Injection Component
// You can reference it in the "opcache.preload" php.ini setting on PHP >= 7.4 when preloading is desired

use Symfony\Component\DependencyInjection\Dumper\Preloader;

if (in_array(PHP_SAPI, ['cli', 'phpdbg'], true)) {
    return;
}

require '/var/www/sites/2.0.0/vendor/autoload.php';
require __DIR__.'/ContainerK8hK1nt/myappMYAPP_DistributionBundle_App_MyAppKernelProdContainer.php';

$classes = [];
$classes[] = 'Oneup\FlysystemBundle\OneupFlysystemBundle';
$classes[] = 'MyApp\ResourceBundle\MyAppResourceBundle';
$classes[] = 'MyApp\UtilityBundle\MyAppUtilityBundle';
$classes[] = 'MyApp\PaymentOmniBundle\MyAppPaymentOmniBundle';
$classes[] = 'MyApp\ExtensionBundle\MyAppExtensionBundle';
$classes[] = 'MyApp\FormBundle\MyAppFormBundle';
$classes[] = 'MyApp\InventoryBundle\MyAppInventoryBundle';
$classes[] = 'MyApp\SecurityBundle\MyAppSecurityBundle';
@michaljusiega
Copy link
Contributor

See:
#38063
#38343
symfony/recipes#825

@yellow1912
Copy link
Author

yellow1912 commented Nov 12, 2020

Thank you @michaljusiega

From your answer, it seems like #38343 reverted the change to #38063.

I have 1 question if you don't mind: coming from SF3, we are using the latest SF4 version with the bundle structure from SF3 instead of the recipes in SF4.

Looking at the code you linked to:

opcache.preload=/path/to/project/src/preload.php

I'm looking at my whole application structure and it doesn't seem like we are having the src folder (we have app, vendor, web folders. Our code are all inside vendor/ourname/ourbundle). Do I need to start using recipes now for this to work?


Edit 1:

After checking the preload file in more details, it seems like for our use case it wont work for now. The problem is the container:

require __DIR__.'/ContainerK8hK1nt/myappMYAPP_DistributionBundle_App_MyAppKernelProdContainer.php';

Right now the container contains both the service definition and the paramterers. While all our service definition remains the same for every site, the parameter will be slightly different. I wonder why we need to include that container file though? Perhaps I can hack around by skipping it?

@michaljusiega
Copy link
Contributor

I am not sure if I can help you. Sorry : <

@jderusse
Copy link
Member

What's about using the same folder for all the website and using environment variables defined in Nginx/Apache to configure database/local/etc... ?

@derrabus
Copy link
Member

Do I need to start using recipes now for this to work?

During cache warmup, a preload script is dumped into your Symfony cache folder, whereever that is in your scenario. This feature should be usable without Flex and recipes.

@nicolas-grekas
Copy link
Member

I'm closing because this looks like a request that relies on an outdated state of the topic.
As of now, a preloading file is generated in the var/cache/ directory, and this file should not be referenced directly, but via another one under your direct control - e.g. in config/preload.php as provided by recipes.

@stof
Copy link
Member

stof commented Nov 24, 2020

Also, be careful about your use case: you said that you have separate Twig templates, but TwigBundle also preloads the compiled template classes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants