14

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 ?

Stephan Vierkant
  • 9,674
  • 8
  • 61
  • 97
Ben
  • 141
  • 1
  • 1
  • 5
  • (for PHP 7.1.9, Apache 2.4.27, MariaDB 10.2.8) – Ben Jan 19 '18 at 17:28
  • What's going on in your controller? It seems to take most of the request handling. Are there any subrequests? – Jakub Zalas Jan 19 '18 at 21:08
  • In this specific example: almost nothing. It only gets the DoctrineManager and a Repository, then returns an empty array (for minimalist test). So no subrequest. But the problem seems to occure before – Ben Jan 19 '18 at 22:53
  • 3
    Try without any database first. Just return a text response. Use a debugger to see what's slowing everything down (network? filesystem?). Do you use a mounted filesystem? – Jakub Zalas Jan 20 '18 at 12:24
  • Have you solved it somehow? – fracz Feb 13 '18 at 20:22
  • Not at all... I tried in disabling almost everything, but all is still slow. Now I only found 2 poor solutions: work with Symfony3.1 or an Ubuntu session – Ben Feb 15 '18 at 11:58
  • Tried without database, like @JakubZalas suggested? – Stephan Vierkant Jun 27 '18 at 10:37
  • 1
    Linux ftw.. but still, shouldn't be slow on Windows, quick google: https://stackoverflow.com/questions/9854848/windows-7-php-symfony2-terribly-slow https://github.com/symfony/symfony/issues/22712 – treyBake Jun 27 '18 at 10:37
  • I did not success to solve problem (I tried without databasebut it was still the same), and I finally decided to stop using Symfony4 for windows devs. – Ben Jun 28 '18 at 10:49

6 Answers6

3

* 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 :)

enter image description here

plunntic iam
  • 964
  • 1
  • 9
  • 18
  • if you want to benefit from this initialization time on wamp/laragon whatever, you can install winnmp like said, but just tick the box "Optimize TCP/IP" (or something similar) during the install (nginx and other stuffs are not needed if you don't want to use them). I don't know what it does exactly but it's worth it. I went from ~2.2sec initialization time to ~225ms after that. – jav974 Jul 20 '22 at 17:04
1
  • 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.

Padam87
  • 1,013
  • 1
  • 6
  • 7
  • Do you have a link available regarding your second point, about JMS DI? – MRoeling Dec 07 '18 at 23:09
  • 1
    I can't give you a link unfortunately, so I will describe. So the bundle service annotations are processed during warmup. And in dev mode every change in a service file triggers a warmup. A large project with many bundles could easily reach 30s warm time this way. What helps is specifying the bundles in the config. http://jmsyst.com/bundles/JMSDiExtraBundle/master/configuration – Padam87 Dec 08 '18 at 02:31
  • Even with bundles specified you will likely see a significant improvement in dev mode (and dev mode only) if you get rid of DI extra. One of my inherited projects went from ~1s to ~180ms just because of this change. And with the new service configuration capabilities, the bundle is pretty much obsolete anyway. – Padam87 Dec 08 '18 at 02:35
  • So if your warmups are slow, but the other requests are fast after the warmup, and you have DI extra installed it is a likely culprit. OP's picture shows a high init time... – Padam87 Dec 08 '18 at 02:40
  • Right, I can imagine. Wondering: would something as [Auryn](https://github.com/rdlowrey/auryn) improve this as well? – MRoeling Dec 10 '18 at 10:47
1

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.

MEmerson
  • 772
  • 1
  • 6
  • 17
0

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

Rmy5
  • 527
  • 8
  • 21
0

On Windows I would recommend WSL2. You can install Apache2 and Mysql and setup a Virtual Host for your project. It runs significantly faster than the build in server.

mabo
  • 1
-1

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.