Windows 7 php + Symfony2 非常慢
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9854848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows 7 php + Symfony2 terribly slow
提问by David Frank
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:
这是我困扰很久的问题。我想在我的 Windows 计算机上运行 PHP 应用程序,它的加载时间非常长,大约 10-25 秒。我尝试了很多事情:
- 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.
- 首先我尝试了一个简单的 XAMPP 安装
- 我读过 WAMP 可能会更快,所以我也尝试了 WAMP。它给了我相同的结果
- 然后我用 PHP 安装了一个 nginx 服务器,但它也没有帮助
- 最后,我在 VirtualBox 中安装了 Ubuntu 11.10 并共享了包含我的项目的 Windows 文件,但结果更糟:每次加载时间超过 22 秒。
UPDATE: I have even tried APC - it improved a bit but still 6-8 sec/page
更新:我什至尝试过 APC - 它有所改善,但仍然是 6-8 秒/页
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.
我将我的文件上传到 linux 服务器(共享主机),它在大约 300-500 毫秒内运行。在 XAMPP 安装中,我也尝试运行其他(即不是 Symfony2)应用程序(例如 phpmyadmin),这些应用程序也比共享主机慢,但不是特别慢,加载时间为 2-3 秒。在我改用 Linux 作为主要操作系统之前,我如何提高性能?我有一台配备 i7 CPU、4 GB RAM、5400RPM 硬盘、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.
UPDATE2:出于某种神秘的原因,我的 Symfony 路由不能与 fcgid 一起使用(它给了我一个 404 错误)所以我回去使用 PHP 作为模块。现在,它已经成为有史以来最糟糕的(比以前作为模块更糟糕):应用程序模式 20-25 秒,在开发模式下,每次超过 30 秒,所以我收到超时错误,它与或相同没有启用 APC。
Hereyou can see this error. This is reproduceable: each time it reaches a different point of execution within 30s:
在这里你可以看到这个错误。这是可重现的:每次在 30 秒内到达不同的执行点:
采纳答案by halfer
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.
我曾经在 XP 和 Server 2003 上使用 symfony 1 遇到过类似的问题。解决方案是安装 PHP 加速器(对我们来说是 eAccelerator,现在 APC 可能是更好的选择)加上 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, YMMV. As per my earlier comment, I recommend asking your question at Apache Lounge, where I previously have received some great expert advice.
附录:自从我在 Windows 上使用 Apache 已经有很长时间了。我一直认为它的性能一直在稳步提高,而不是更糟;然而,与大多数不寻常的设置一样,YMMV。根据我之前的评论,我建议您在Apache Lounge提问,我之前在那里收到了一些很棒的专家建议。
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.
如果没记错的话,他们可以为您提供一个免费的 Apache 二进制文件,该二进制文件使用比 Apache 网站上提供的标准工具更好的工具编译。
回答by Simon Fakir
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.
由于 PHP 5.5 现在集成了 PHP OPCache,这加快了执行时间。在我的设置中,具有数据库访问权限的完整请求现在需要 180 毫秒。
Steps:
脚步:
- Update to the latest php version
- Enable OPCache
- Disable xdebug
- Set realpath_cache_size = 2M as DemonTPx mentioned
- 更新到最新的php版本
- 启用 OPCache
- 禁用 xdebug
- 设置 realpath_cache_size = 2M 作为 DemonTPx 提到
php.inisettings:
php.ini设置:
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?
为什么 Windows 比 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.
正如此处所讨论的,PHP 在 file_exists 和 Windows 上的 filemtime() 中非常慢。因为 Symfony2 在开发模式下经常使用这些功能。在 Windows 上我们不会低于 700 毫秒(<= 5.4)。PHP 5.5 现在允许 180 毫秒。
A solution could be WinCachewhich 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.
一个解决方案可能是由微软开发的WinCache来解决 IIS 上的这个问题。但由于它仅适用于多个 Windows 版本,而且仅适用于 IIS,因此对我来说不是解决方案。
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.
我可以推荐的另一个不错的解决方案是在 Virtualbox 上安装 Linux 虚拟机。这很容易设置,也更像是生产环境。
回答by Bert Hekman
I have the exact same problem. Setting the following in php.ini increased the performance for me from ~800ms to ~300ms:
我有完全一样的问题。在 php.ini 中设置以下内容将我的性能从 ~800ms 提高到 ~300ms:
php.ini:
php.ini:
realpath_cache_size = 2M
Still not the ~100ms I get from a unix machine, but it makes a difference at least
仍然不是我从 unix 机器上得到的大约 100 毫秒,但至少有所不同
回答by Sébastien
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.
哇,在尝试了许多不同的事情之后,我终于成功地在 windows7 上使用 wamp 从 15 秒的执行时间转移到了 3 秒的执行时间。
How to install wincache extension : http://us2.php.net/manual/en/wincache.installation.php
如何安装 wincache 扩展:http: //us2.php.net/manual/en/wincache.installation.php
Where to download the wincache dll: http://sourceforge.net/projects/wincache/
wincache dll下载地址:http: //sourceforge.net/projects/wincache/
My php.ini config change:
我的 php.ini 配置更改:
[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
回答by Ekrem
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.
我认为您的缓存机制有问题。检查 app\cache 目录。必须有一个名为 dev 的文件夹。如果它不存在或为空,请检查文件夹权限。当我删除 app\cache 目录下的 dev 和 prod 目录时,加载页面需要 18 秒,但之后只需要 500 毫秒。
回答by Vincent
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)
几年前,我遇到了同样的问题。您在后台运行哪些防病毒软件?尝试出于开发目的停用它或更改它。它也可能是一些在后台运行的索引服务。Symfony 2 由超过 15000 个供应商的文件组成 :) 也尝试通过从头开始重新安装 Windows 来使用经典方法。我的网站通常需要 100-500 毫秒,而我的笔记本电脑比你的慢。(英特尔 C2D P8600)
回答by Wouter
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?
只是一个猜测(可能不是正确的),但它可能与 MySQL 相关。看到您如何提到 PhpMyAdmin 和 Symfony 2 作为您测试的 PHP 应用程序,它们都依赖于 MySQL(假设您在 Symfony 2 中设置了 MySQL)。您在帖子中没有提到这一点,但是在您的 VirtualBox 设置中,您是否曾让运行在 Ubuntu 上的脚本连接到您的 Windows 主机上的 MySQL 服务器?
You could check out PHP Benchmarkfor some performance testing scripts, and see if these scripts perform better timewise.
您可以查看一些性能测试脚本的PHP Benchmark,看看这些脚本在时间上是否表现得更好。
Another thing you could try is use Xdebugand see if you find (a) certain (group of) function(s) that are taking up too much time.
您可以尝试的另一件事是使用Xdebug,看看您是否发现 (a) 某些(一组)函数占用了太多时间。
I'm definately gonna keep this question as a favorite, because I am too curious to see what it was now :) good luck !
我肯定会把这个问题作为最喜欢的,因为我太好奇了,看不到它现在是什么:)祝你好运!
回答by Wouter
Check your computer random access memory, RAM using http://oca.microsoft.com/en/windiag.aspor run the memory test application shipped with your Ubuntu CD booting option.
使用http://oca.microsoft.com/en/windiag.asp检查您的计算机随机存取存储器、RAM或运行您的 Ubuntu CD 引导选项附带的内存测试应用程序。
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.
在这两种情况下,选择所谓的额外或深度测试 - 我不记得了 - 但是,选择更长时间的测试这些类型的测试没有结束,您只需等到测试完成两个阶段以及您的任何问题RAM,通常显示。
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.
我有点,你的问题是硬件相关的问题。
回答by Alex
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:
我的页面需要 20 秒才能执行。我安装了快速 cgi,增加了内存限制,一切都不起作用。然后开始查看时间线并注意到 symfony 防火墙模块占用了大部分时间。原来在我的教义配置中使用“localhost”是导致问题的原因。将其更改为 127.0.0.1 解决了问题。不知道为什么,但它在这里描述:
http://12wiki.blogspot.ca/2012/11/why-does-symfony-2-firewall-take-so.html
http://12wiki.blogspot.ca/2012/11/why-does-symfony-2-firewall-take-so.html
回答by Kumar
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.
页面加载时间也取决于 CSS + JS + 图片加载时间。我在 CakePHP 中遇到了同样的问题,并通过mod_expires
在 htaccess 中使用解决了这个问题。
Have you tried "ExpiresByType" in your server htaccess file for CSS, JS and images? Check thispage.
您是否在服务器 htaccess 文件中为 CSS、JS 和图像尝试过“ExpiresByType”?检查此页面。