Windows 7 php + Symfony2 terribly slow
Asked Answered
S

11

36

This is an issue I've been having for a long time. I want to run PHP applications on my windows computer and it has a terribly high load time, around 10-25 seconds. I have tried many things:

  • First I tried a simple XAMPP installation
  • I read WAMP might be faster, so I tried WAMP, too. It gave me the same results
  • Then I installed an nginx server with PHP, but it did not help either
  • Finally, I installed an Ubuntu 11.10 in VirtualBox and I shared my windows files containing my project, but the result was even worse: over 22 second load time each time.

UPDATE: I have even tried APC - it improved a bit but still 6-8 sec/page

I uploaded my files to a linux server(shared hosting), on which it runs in around 300-500 ms. On the XAMPP installation I tried to run other (i.e. not Symfony2) applications as well(e.g. phpmyadmin), which too were slower than on the shared hosting, but not extremely slow, with 2-3 sec load time. Until I change to Linux as the main OS, how could I improve performance? I have a laptop with i7 CPU, 4 GB RAM, 5400RPM HDD, Win7 x64.

Thank you for your help!

UPDATE2: For some mysterious reason my Symfony routing didn't work with fcgid (it gave me a 404 error for everything) so I went back for using PHP as a module. Now, it has become the worst ever (worse than it used to be as a module): app mode 20-25 sec, and in dev mode, over 30s every time, so I get a timeout error, and it's the same with or without APC enabled.

Here you can see this error. This is reproduceable: each time it reaches a different point of execution within 30s:

enter image description here

Slopwork answered 24/3, 2012 at 19:34 Comment(24)
If APC gave you no improvement, I'd suspect it was misconfigured. I can't think that having a PHP accelerator would make no difference at all with any application, even if PHP processes stayed in memory via FastCGI. Does APC offer a web application to peek into the opcode cache? We had this for eAccelerator, which I guess would have been useful if pages weren't caching.Weixel
Now I'm going to retry with APC, and tell you the results.Slopwork
Results: it is better now, but still 6-8 sec/page. Any idea?Slopwork
What did you change? If APC offered an improvement, then you may wish to edit your post to reflect that, and save on confusion :)Weixel
I have provided two other ideas on my answer below.Weixel
I enabled the apc extension, and changed symfony2 autoload according to this: symfony.com/doc/current/book/performance.htmlSlopwork
Do you measure Symfony2 performance in dev mode or in prod mode? What does profiler say?Gibson
I see the load time in dev mode, but it isn't faster in prod mode either.Slopwork
Hmm... screenshot the profiler (especially any timings data) and paste it into your question.Weixel
I updated the question, please have a look. Now it's even worse.Slopwork
Hmm. Is this action empty? - to check raw performance you should just be serving a hello world string. Personally I'd persist with fcgid. It worked for me pretty easily, but it's been a few years since I set that up on Windows.Weixel
(Aside: if you get stuck, then grab yourself a copy of VirtualBox, install it on your Windows machine, and install a LAMP server inside it. That will get you up and running pretty quickly)Weixel
As I wrote above ubuntu in virtualbox wasn't better. I made a benchmark test(source: frankdavid.hu/files/benchmark.php.txt), it runs in 600-800ms while on the linux server it runs in less than 1ms!Slopwork
@DavidFrank - I've run out of things to suggest, but ~600ms isn't too bad for what I presume is a dev machine. It is quite possible to dev on Windows and deploy on Linux (surely "ubuntu in virtualbox wasn't better" can't be the case, if you're getting 600ms instead of 30s!).Weixel
No, you must have misunderstood me. 600 ms is the runtime of the test script on windows while on the linux hosting(remote machine) its under 1ms. I did not run the benchmark on my virtualbox ubuntu. Ubuntu runs my symfony2 project in 20-25 sec.Slopwork
Have you installed and not running Adobe ColdFusion service on the same machine?Gilbert
@DavidFrank - well, I was just repeating what you said: "As I wrote above ubuntu in virtualbox wasn't better. I made a benchmark test... it runs in 600-800ms while on the linux server it runs in less than 1ms". However, I am now properly confused: "Ubuntu runs my symfony2 project in 20-25 sec". I thought it was Windows that was the very slow one?Weixel
Allow me to repeat my previous suggestion: "screenshot the profiler (especially any timings data) and paste it into your question" (from the machine with 20-25sec timings).Weixel
Now it loads in 10-15s again, but I dont see any timings data in my profiler, although I checked all the pages multiple times. I only see these lines in the log: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\RouterListener::onEarlyKernelRequest".Slopwork
Did you find solution? I have some problem. PHP work fine in my Ubuntu, but pretty slow on Windows.Cocksure
No, I did not. Even php5.4 is so slow on my laptop.Slopwork
@Cocksure - paste your screenshot of your timing profile into a link in the comments - otherwise there's nothing much fresh to go on. If you are a confident debugger, try isolating the part of Symfony2 that is causing the slow-down. Just guessing - could be a file system call that isn't cached on Windows?Weixel
I got fed up with the whole thing and removed the webserver from my computer. Maybe later I'll reinstall it, then I'll send screenshots. All I can tell you is everything is slow. I tried with different projects, different sf versions(2.0, 2.1), different php versions(5.3.* TS, NTS, 5.4), it was slow in the console(running sf commands) and in the browser, too. So it seems to me to be a common issue. Edit: I've just noticed your message wasn't addressed to me, whatever...Slopwork
I have the same problem: symfony2 project load time is 8 to 15 seconds on wamp windows and less than 500ms on my remote server running ubuntu (a very basic 2€/month solution). I've tried many php config changes for no result...Metaphase
W
9

I had a similar problem with symfony 1 for a time on XP and Server 2003. The solution was to install a PHP accelerator (eAccelerator for us, APC might be a better bet these days) plus FastCGI/fcgid.

Addendum: it's been ages since I've used Apache on Windows. I have generally been of the view that its performance has been getting steadily better, rather than worse; however as with most unusual set-ups, good results are not guaranteed. As per my earlier comment, I recommend asking your question at Apache Lounge, where I previously have received some great expert advice.

If memory serves correctly, they can offer you a free Apache binary compiled with better tools than the standard one offered on the Apache website.

Weixel answered 24/3, 2012 at 19:38 Comment(4)
I have tried APC but didnt help, and with fastCGI it became even slower.Slopwork
I upgraded to fcgid, but didnt help :( I even got an NTS version of PHPSlopwork
Did you verify that it was actually installed? You should have a Symfony toolbar that lets you know whether it is working (at least, symfony 1 had one). I believe also that either php or apache (I forget which) should show that fcgid is correctly installed if you list modules at the command line.Weixel
Symfony2 has a toolbar, too, and yes, after I had activated the APC, symfony2 indicated it. About the fcgid: in the task manager, I see php-cgi.exe, althought, I didnt see it earlier.Slopwork
P
27

Update:

Since PHP 5.5 has now integrated the PHP OPCache, this speeds up the execution time. In my setup a full request with database access takes 180ms now.

Steps:

  1. Update to the latest php version
  2. Enable OPCache
  3. Disable xdebug
  4. Set realpath_cache_size = 2M as DemonTPx mentioned

php.ini settings:

realpath_cache_size = 2M
[XDebug]
xdebug.profiler_enable = 0
xdebug.remote_enable = 0
[opcache]
zend_extension = "C:\xampp18\php\ext\php_opcache.dll"
opcache.enable = 1
opcache.enable_cli = 0
opcache.memory_consumption = 128
opcache.interned_strings_buffer = 8
opcache.max_accelerated_files = 4000

Why is Windows slower than Unix?

As discussed here, PHP is very slow in file_exists, and filemtime() on Windows. since Symfony2 is using these functions in dev mode a lot. we won't get under 700ms (in <= 5.4) on Windows. PHP 5.5 allows now 180ms.

A solution could be WinCache which was developed by microsoft to solve this problem on IIS. But as it only works on several Windows versions and also only with IIS it's no solution for me.

Alternative

Also a nice solution I can recommend is to have a Linux Virtual Machine on Virtualbox. This is easy to setup and is also more like the production environment.

Prosthodontics answered 10/6, 2013 at 10:0 Comment(3)
I dropped from 10s to 2.5s with those settings. Disabling xDebug made a noticeable improvement, as well as setting realpath_cache_size to 2M.Stilbestrol
Hi Jean, still - 2.5 seconds is to slow for development. You may try OPCache in PHP5.5 which should do it faster.Prosthodontics
That helped me a lot! Lowered loading time from ~500ms to ~50ms. Thanks!Dimitri
R
20

I have the exact same problem. Setting the following in php.ini increased the performance for me from ~800ms to ~300ms:

php.ini:

realpath_cache_size = 2M

Still not the ~100ms I get from a unix machine, but it makes a difference at least

Renatorenaud answered 23/7, 2013 at 17:55 Comment(0)
W
9

I had a similar problem with symfony 1 for a time on XP and Server 2003. The solution was to install a PHP accelerator (eAccelerator for us, APC might be a better bet these days) plus FastCGI/fcgid.

Addendum: it's been ages since I've used Apache on Windows. I have generally been of the view that its performance has been getting steadily better, rather than worse; however as with most unusual set-ups, good results are not guaranteed. As per my earlier comment, I recommend asking your question at Apache Lounge, where I previously have received some great expert advice.

If memory serves correctly, they can offer you a free Apache binary compiled with better tools than the standard one offered on the Apache website.

Weixel answered 24/3, 2012 at 19:38 Comment(4)
I have tried APC but didnt help, and with fastCGI it became even slower.Slopwork
I upgraded to fcgid, but didnt help :( I even got an NTS version of PHPSlopwork
Did you verify that it was actually installed? You should have a Symfony toolbar that lets you know whether it is working (at least, symfony 1 had one). I believe also that either php or apache (I forget which) should show that fcgid is correctly installed if you list modules at the command line.Weixel
Symfony2 has a toolbar, too, and yes, after I had activated the APC, symfony2 indicated it. About the fcgid: in the task manager, I see php-cgi.exe, althought, I didnt see it earlier.Slopwork
S
3

Wow, After trying many different things, I've finally succeeded to move from a 15s execution time to a 3s exec time on windows7 with wamp.

How to install wincache extension : https://www.php.net/manual/en/wincache.installation.php

Where to download the wincache dll: http://sourceforge.net/projects/wincache/

My php.ini config change:

[PHP]
realpath_cache_size = 2M
extension=php_wincache.dll
; XDEBUG Extension
;zend_extension = "C:/Net Generation/wamp/bin/php/php5.5.12/zend_ext/php_xdebug-2.2.5-5.5-vc11.dll"
;
[xdebug]
xdebug.remote_enable = off
xdebug.profiler_enable = Off
xdebug.profiler_enable_trigger = off
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir = "C:/Net Generation/wamp/tmp"
xdebug.show_local_vars=0
xdebug.max_nesting_level=200

[opcache]
zend_extension = "C:/Net Generation/wamp/bin/php/php5.5.12/ext/php_opcache.dll"
opcache.enable = 1
opcache.enable_cli = 0
opcache.memory_consumption = 128
opcache.interned_strings_buffer = 8
opcache.max_accelerated_files = 4000
Salo answered 27/1, 2015 at 14:20 Comment(0)
W
1

i think you have a problem with caching mechanism. check app\cache directory. there has to be a folder named dev. if it does not exist or if it is empty check folder permissions. when i delete dev and prod directories under app\cache directory it takes 18 seconds to load the page but after that it takes only 500 ms.

Woodcraft answered 3/4, 2012 at 0:1 Comment(1)
My caching seems to be working perfectly, and as I said, I have this problem not only with symfony apps.Slopwork
A
1

Some years ago i had the same problem. Which antivirus software do you run in the background? Try to deactivate it for dev purposes or change it. It also could be some indexing services running in the background. Symfony 2 consists of >15000 files with vendors :) Also try to do it the classic way by reinstalling Windows from the scratch. My sites takes usually from 100-500ms and my laptop is slower than yours. (Intel C2D P8600)

Apeldoorn answered 9/4, 2012 at 15:6 Comment(1)
No, I dont have an anti-virus.Slopwork
M
1

Just a guess (and probably not the right one), but it could be MySQL related. Seeing how you mentioned PhpMyAdmin and Symfony 2 as PHP applications you tested, both rely on MySQL (assuming you have MySQL set up in Symfony 2). You did not mention this in your post, but in your VirtualBox setup, did you by any chance let the script running on Ubuntu connect to the MySQL server on your Windows host machine?

You could check out PHP Benchmark for some performance testing scripts, and see if these scripts perform better timewise.

Another thing you could try is use Xdebug and see if you find (a) certain (group of) function(s) that are taking up too much time.

I'm definately gonna keep this question as a favorite, because I am too curious to see what it was now :) good luck !

Mandy answered 27/7, 2012 at 14:29 Comment(1)
omg Wouter, thank you so much. I was banging my head against the wall with a similar problem and you are absolutely right - my remote MySQL connection was the bottleneck.Arianna
G
0

Check your computer random access memory, RAM using http://oca.microsoft.com/en/windiag.asp or run the memory test application shipped with your Ubuntu CD booting option.

In both cases choose what know as extra or deep test - I don't remember exactly- How ever, choose the test with more longtime these kind of tests has no end, you just wait till the test finish two phases and any problems with your RAM, commonly, shown.

Also, Check your hard drive with any mean of checking. after that try to perform disk defragmentation

I bit, your problem is hardware related problem.

Gemini answered 28/7, 2012 at 11:32 Comment(0)
T
0

My pages were taking 20 seconds to execute. I installed fast cgi, increased memory limits, everything, not working. Then started looking at timeline and noticed symfony firewall module was taking up most of it time. Turns out having "localhost" in my config for doctrine is what was causing issues. Changing it to 127.0.0.1 fixed the problem. Not sure why, but it's described here:

http://12wiki.blogspot.ca/2012/11/why-does-symfony-2-firewall-take-so.html

Tacho answered 17/5, 2015 at 0:25 Comment(0)
F
-1

Page loading time is depends on the CSS + JS + Image loading time also. I had the same problem in CakePHP and solved the problem by using mod_expires in htaccess.

Have you tried "ExpiresByType" in your server htaccess file for CSS, JS and images? Check this page.

Firecracker answered 24/7, 2012 at 5:4 Comment(0)
S
-2

Whoever google this in 2023 - PHP is just slow on Windows with its basic functions like is_dir() which takes 5-8 more time than on Linux. In a big project like Symfony or Drupal there are like 100k of such calls which makes them very slow on Windows.

Sirreverence answered 22/11, 2023 at 18:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.