8000 [Dependency-Injection] OPcache preload-file not being generated · Issue #34897 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Dependency-Injection] OPcache preload-file not being generated #34897

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
Kleinkind opened this issue Dec 9, 2019 · 5 comments
Closed

[Dependency-Injection] OPcache preload-file not being generated #34897

Kleinkind opened this issue Dec 9, 2019 · 5 comments

Comments

@Kleinkind
Copy link
Kleinkind commented Dec 9, 2019

Hello :)

Symfony version(s) affected: >= 4.4.0

Description
We tried to enable opcache preloading on php 7.4 but the App_KernelProdContainer.preload.php file is not being generated. For our cache we use a custom directory outside of the project-directory. This is accomplished by overriding getCacheDir in the Kernel. If we use the default implementation of getCacheDir the generated cache contains the preload file.

How to reproduce

  • Override the Kernels getCacheDir-Function and return a custom cache-dir outside of the projects path.
public function getCacheDir(): string
{
	# different from kernel.project_dir
    return '/var/application/cache/'.$this->environment;
}
  • run bin/console cache:clear --env=prod
  • no preload-file present under /var/application/cache/prod/

Possible Solution
In the PhpDumper-Class the autoload-file for the project is determined in the getAutoloadFile-method. The autoloader-file is only returned if it's path matches the $this->targetDirRegex, which is based on the target directory for the cache. This regex would match any autoloader contained in two directories higher than the cache-dir itself. Therefore it works if your cache is stored in %PROJECT_DIR%/var/cache/prod, but not if it is stored somewhere else.
The determination of the autoloader should therefore also/only include any files found under kernel.project_dir.
If my assumptions are correct I would happily provide a pull-request and try to fix this.

Additional context

  • We use /var/application/cache for our cache and /var/www/symfony for the project itself.
  • We use docker's bind-mount to mount the project into the container (on dev, in production the code is contained in the image) and a standard docker volume to share the cache between different services.
@Kleinkind Kleinkind changed the title opcache preload-file not being generated [Dependency-Injection] OPcache preload-file not being generated Dec 9, 2019
@nicolas-grekas
Copy link
Member

Duplicate of 8000 #34750 and #34611, fixed #34757.

@guilliamxavier
Copy link
Contributor

This is fixed in the case where both dirs are subdirs of the same hierarchy (/var/** in the reported context), but
I'm still having the issue (Symfony 4.4.10, PHP 7.4.7) in a case where the dirs paths don't have a common prefix (beyond the root):
  project dir: /usr/src/app
    cache dir: /var/app/cache
(note: forcing the parameter container.dumper.inline_class_loader to true doesn't seem to make a difference).
Is that an absolute limitation?

@nicolas-grekas
Copy link
Member

I think so yes.

@guilliamxavier
Copy link
Contributor
guilliamxavier commented Jul 8, 2020

OK, that's unfortunate 🙁 but thanks for confirming 👍

@chdeliens
Copy link

@nicolas-grekas Is the limitation a PHP or a Symfony one?

If Symfony: I'm then wondering about the point of being able to override the default getCacheDir() if it's not used in the "preload" context?

Thanks for your feedback on this, as our current container build strategy is having /app read-only for the app, then mount a writable /tmp folder inside the container.

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

6 participants
0