PHP dotEnv library as a bottleneck
I had used a popular library https://github.com/vlucas/phpdotenv for many years in my PHP projects built on Yii framework. The library is easy to use and always worked well.
Recently I tried to find performance bottlenecks in my application and used Xdebug profiler. A big surprise: my app start took around 100ms due to configuration loading, and the longest time was .env file parsing. Also there was a big memory usage (about 1MB of memory to parse a 2KB text file).
Solution: migration to another library, Symfony dotenv: https://github.com/symfony/dotenv. It required changing just few lines of code.
Results, server response p90 latency (deployed around 10th of March):
Subscribe to my newsletter
Read articles from Michael Krutikov directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by