Skip to content
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

Enable opcache and use it with the file cache #14

Merged
merged 5 commits into from
Jun 8, 2018
Merged

Enable opcache and use it with the file cache #14

merged 5 commits into from
Jun 8, 2018

Conversation

mnapoli
Copy link
Member

@mnapoli mnapoli commented Jun 8, 2018

Opcache usually works in memory, compiling PHP code to opcode and caching it in memory between HTTP requests. Since on lambdas the PHP process is terminated between requests, the classic behavior of opcache doesn't work (the cache is cleared every time).

To make opcache work we enable its "file cache" mode where opcache writes the opcode into a file (with the opcache.file_cache option). When the PHP process starts, it reads the opcodes from the file cache.

Opcache usually works in memory, compiling PHP code to opcode and caching it in memory between HTTP requests. Since on lambdas the PHP process is terminated between requests, the classic behavior of opcache doesn't work (the cache is cleared every time).

To make opcache work we enable its "file cache" mode where opcache writes the opcode into a file (with the `opcache.file_cache` option). When the PHP process starts, it reads the opcodes from the file cache.
@mnapoli
Copy link
Member Author

mnapoli commented Jun 8, 2018

OK I think I understand why I don't see any difference in performances, what I did is not enough for opcache to get loaded. I need to bundle the opcache.so file too it seems.

@mnapoli
Copy link
Member Author

mnapoli commented Jun 8, 2018

On the API platform demo, when getting a list of books (uses the database):

  • without opcache: 220ms
  • with opcache: 105ms

This is very good news, it means opcache in CLI mode is very useful too.

@mnapoli mnapoli merged commit 60a5c36 into master Jun 8, 2018
@mnapoli mnapoli deleted the opcache branch June 8, 2018 13:09
@fgilio
Copy link

fgilio commented Jun 8, 2018

Impressive! Thanks 🙌🏼

This was referenced Jun 12, 2018
jvis pushed a commit to jvis/bref that referenced this pull request Nov 1, 2018
Enable opcache and use it with the file cache
@staabm
Copy link
Contributor

staabm commented Nov 16, 2018

to be honest, I dont get why the file-based opcache works. will the opcache file, which gets created on the first visit be persisted with the lambda and is available on subsequent requests?

or do you somehow pre-generated the opcache while deployment or similar, and therefore the opcache-file-cache is part of the "software-package" as a whole?

@wysow
Copy link

wysow commented Nov 16, 2018

@staabm lambdas are warm after the first call (cold start) for approx. 45 minutes (at least that was the case when I last checked), this is to optimize infrastructure resources on AWS side, so opcache is OK for this time at least.

@mnapoli
Copy link
Member Author

mnapoli commented Nov 16, 2018

👍 and I want to explore the possibility of generating the opcache file before deploying. That would probably require using a Docker image with the exact same PHP version and same file paths, but I was told on Twitter that this could be doable.

brefphp-bot pushed a commit to brefphp-bot/bref that referenced this pull request Nov 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants