Symfony 4 extremely slow on windows

蓝咒 提交于 2020-12-29 03:20:06

问题


I've used Symfony on Windows 10 for my projects for a few years (SF2, SF3), and I recently moved to Symfony 4 to build a new project but performances are catastrophic.

Symfony initialization time takes from 5 to 25s, as in this example example

It is the same with console: for example a cache:clear can last 1 minute.

I searched for similar problems and issues in Symfony doc and forums, and I've tested recommended optimizations (increase some values for ​​opcache, enable APCu, disable xdebug, add realpath_cache_size in php.ini, use Composer Class Map Functionality) but in my case it does not change anything.

Here are my phpinfo for APCu: APCu and Opcache: opcache

I'm using PHP 7.1.9, Apache 2.4.27, MariaDB 10.2.8.

Is there someone with same problems and/or ideas ?


回答1:


* update *

I've found an even better solution for this problem. That is... vagrant. I know what you're thinking - "Vagrant on windows? Lol.". But here's what changed - there's now a plugin for NFS folder sync on windows. I've tested it on two win10 pc's and so far so good. It seems very stable for me, and i'm getting response times as low as 40-50 ms (except for the times when symfony is regenerating/warming cache etc of course). Composer installs, IDE synchronization & other stuff all working fine too.

Besides that i have fairly standard setup consisting of nginx and php7.2-fpm on ubuntu bionic virtualbox VM. Nothing special or optimised in any way.

If you're not in to vagrant much i still leave my older answer below for reference. Good luck and happy coding!

* // update *

Symfony has always been very poor in terms of performance on windows, at least for me anyway.

Enabling / disabling opcache / apc / xdebug, tweaking realpath or whatever can - probably - make things better, at least a little bit, but never really works in my experience. And... who on earth wants to work without a debugger? That's not a solution in my opinion.

My recommendation is to completly remove XAMPP / WAMP (or however you've installed your current php stack) and install nginx + php-fpm.

You can do it by hand - for example - or by installing WinNMP.

WinNMP is a tool very simillar to XAMPP / WAMP, but based on nginx. It comes with Nginx, PHP, MySQL and Redis.

The only downside is you have to learn how to configure nginx - if you don't know - but you should anyway. Nginx is more performant and thus - in most cases - better suited for production environment, so it may be helpful in the future.

Anyway that's the only viable solution i've found to use symfony on windows where i don't have to disable xdebug or wait ages on every refresh :)




回答2:


  • Are you using localhost to connect to the db (or anything)? Change it to 127.0.0.1

  • JMS DI Extra bundle can do this on windows if not configured properly.

  • Others have mentioned xdebug and realpath_cache_size, those are also regular culprits.




回答3:


Use built-in dev server instead of WAMP. Install dev server bundle:

composer require --dev symfony/web-server-bundle

Run server:

php bin/console server:run




回答4:


I had a Symfony problem with initialization taking 3-5 seconds for every single request, which made local development very slow. I tried everything for improving it (php.ini setting changes, upgrading php, etc), I finally walked through Symfony starting up in xDebug and found that the dev cache was being rebuilt every single page request and that the file services.yaml was triggering the cache rebuild.

When I looked at the Services.yaml file I realized that the modified time was way in the future, because I was testing time changes and had moved my computer time into the future and saved the services.yaml file during that. When I re-saved the file in the current time it stopped forcing the cache to be rebuilt every time.




回答5:


Same here, I have windows 10 Professional, using XAMPP ( Tryed php 5 and php 7, doesnt matter wich one).

I've also tryed using the built server with php bin/console server:run

I'm working json response controllers, it takes about 30 to 45 secs tu run, sometimes even more than a minute to process. My Api request even return timeout error.

Also, every operatioin I do with php bin/console are terrible slow.. so I think isnt just Apache in XAMMP but the PHP bundle distributed with it.

I've just installed php-7-2 package from http://windows.php.net and now It works so much better. Responses are up to 3-4 seconds.

So dont waste your time using XAMPP... just go for original PHP and Apache and thats it.



来源:https://stackoverflow.com/questions/48346427/symfony-4-extremely-slow-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!