php Win7 上的 XAMPP 太慢
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1891031/
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
XAMPP on Win7 too slow
提问by Martin
I'm running XAMPP 1.7.1 on Windows 7 Ultimate. Everything (Apache & MySQL) is working fine except for speed.
我在 Windows 7 Ultimate 上运行 XAMPP 1.7.1。除了速度之外,一切(Apache 和 MySQL)都运行良好。
When I open http://localhost/, I must wait probably 1-3 seconds for view a webpage. In my opinion, it should be at most some hundreds miliseconds.
当我打开http://localhost/ 时,我必须等待大约 1-3 秒才能查看网页。在我看来,最多应该是几百毫秒。
Basic facts:
基本事实:
- while waiting to load a localhost webpage, status bar says "Waiting for localhost..."
- CPU is still idle (no increased activity while loading)
- on localhost is no demanding PHP scripts, problems are when there is simple phpinfo() even if there is long heavy scripts.
- disabling MySQL server don't affect speed
- my PC: AMD Turion 64 X2; 1,6 GHz dual-core, 2 GB RAM, 100 GB HDD
- 在等待加载本地主机网页时,状态栏显示“正在等待本地主机...”
- CPU 仍然空闲(加载时没有增加活动)
- 在 localhost 上不需要 PHP 脚本,问题是当有简单的 phpinfo() 时,即使有很长很重的脚本。
- 禁用 MySQL 服务器不会影响速度
- 我的电脑:AMD Turion 64 X2;1,6 GHz 双核,2 GB RAM,100 GB 硬盘
I've made a little simple benchmark PHP script to test HDD/CSS speeds:
我制作了一个简单的基准 PHP 脚本来测试 HDD/CSS 速度:
<?php
function getmicrotime() {
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
function testReadWrite() {
$timeStart = getmicrotime();
$filename = "test.txt";
file_put_contents( $filename, '' ); // prepare empty file
for ( $i = 0; $i < 1000; $i++ ) {
$a = file_get_contents( $filename );
file_put_contents( $filename, $a . '.' );
}
return round( getmicrotime() - $timeStart, 3 );
}
function testCpuSpeed() {
$timeStart = getmicrotime();
$var = '';
for ( $i = 0; $i < 100000; $i++ ) {
$var = sha1( md5( $i * $i * $i * $i * $i * $i * $i * $i * $i * $i ) );
}
return round( getmicrotime() - $timeStart, 3 );
}
echo "Read/write #1: " . testReadWrite() . "<BR>";
echo "Read/write #2: " . testReadWrite() . "<BR>";
echo "Read/write #3: " . testReadWrite() . "<BR>";
echo "CPU speed #1: " . testCpuSpeed() . "<BR>";
echo "CPU speed #2: " . testCpuSpeed() . "<BR>";
echo "CPU speed #3: " . testCpuSpeed() . "<BR>";
?>
My PC results:
我的电脑结果:
- Read/write: 5.134 / 3.431 / 3.494
- CPU speed: 0.816 / 0.767 / 0.795
- 读/写:5.134 / 3.431 / 3.494
- CPU 速度:0.816 / 0.767 / 0.795
A webhosting results:
虚拟主机结果:
- Read/write: 7.768 / 7.69 / 7.371
- CPU speed: 0.232 / 0.234 / 0.234
- 读/写:7.768 / 7.69 / 7.371
- CPU 速度:0.232 / 0.234 / 0.234
One of my server's results (as idle computer nearly as my PC, but a little bit faster):
我的服务器的一个结果(闲置的计算机几乎和我的 PC 一样,但要快一点):
- Read/write: 0.088 / 0.168 / 0.185
- CPU speed: 0.191 / 0.189 / 0.189
- 读/写:0.088 / 0.168 / 0.185
- CPU速度:0.191 / 0.189 / 0.189
So I don't think that it is because of my PC speed, but I'm sure that there's some another problem. Do you have some experience with XAMPP speed on Windows 7 (or Vista) ?
所以我不认为这是因为我的 PC 速度,但我确定还有一些其他问题。您对 Windows 7(或 Vista)上的 XAMPP 速度有一些经验吗?
Thanks.
谢谢。
回答by JoeV
If XAMP is slow under windows 7, the firewall settings make no difference.
The Security Essentials anti-virus makes no difference.
如果 XAMP 在 Windows 7 下运行缓慢,则防火墙设置没有任何区别。
Security Essentials 防病毒软件没有任何区别。
To solve this problem, the two things that make a big difference are:
为了解决这个问题,有两件事有很大的不同:
1) in windows\system32\drivers\etc\hosts add the following lines:
1) 在 windows\system32\drivers\etc\hosts 添加以下几行:
127.0.0.1 127.0.0.1
127.0.0.1 127.0.0.1
127.0.0.1 localhost
127.0.0.1 本地主机
2) If you're using PHP, in the XAMP php.ini file uncomment the eaccelerator line:
2) 如果您使用的是 PHP,请在 XAMP php.ini 文件中取消注释 eaccelerator 行:
zend_extension = "C:\xampp\php\ext\php_eaccelerator_ts.dll"
zend_extension = "C:\xampp\php\ext\php_eaccelerator_ts.dll"
After these two changes, restart Apache and it will be way faster.
在这两个更改之后,重新启动 Apache 会更快。
回答by Barto
Comment the lines in PHP.ini with XDEBUG:
用 XDEBUG 注释 PHP.ini 中的行:
;[XDebug]
;zend_extension = "C:\xampp\php\ext\php_xdebug.dll"
;xdebug.profiler_append = 0
;xdebug.profiler_enable = 1
;xdebug.profiler_enable_trigger = 0
;xdebug.profiler_output_dir = "C:\xampp\tmp"
;xdebug.profiler_output_name = "cachegrind.out.%t-%s"
;xdebug.remote_enable = 0
;xdebug.remote_handler = "dbgp"
;debug.remote_host = "127.0.0.1"
;xdebug.trace_output_dir = "C:\xampp\tmp"
I disabled Bitdefeender -> no result
I added lines to hosts -> no result
I disabled xdebug - x2-x3 faster
Best regards Barto
最好的问候巴托
回答by Pascal MARTIN
Not sure this might be the cause of your problems, but this might be an idea : do you have a line that looks like this :
不确定这可能是您的问题的原因,但这可能是一个想法:您是否有一条看起来像这样的行:
::1 localhost
in your hosts (it should be somewhere like C:\WINDOWS\system32\drivers\etc\hosts, if I remember correctly)file ?
在您的主机(C:\WINDOWS\system32\drivers\etc\hosts如果我没记错的话,应该在某个地方)文件中?
If yes, comment that line by adding a #at the beginning.
如果是,请通过#在开头添加 a 来注释该行。
This way, the only line that's about localhost should be
这样,关于 localhost 的唯一一行应该是
127.0.0.1 localhost
which is an IPv4 address ; and the one you commented being an IPv6 -- which is quite not useful for what you are trying to do.
这是一个 IPv4 地址;你评论的那个是 IPv6——这对你想要做的事情没有用。
As I said, not sure your problem is related to this, but I've seen this sugestion help a couple of times for problems quite similar to your (i.e. waiting a long time before doing anything on the server).
正如我所说,不确定您的问题是否与此有关,但是我已经看到此 sugestion 对与您的问题非常相似的问题有几次帮助(即在服务器上执行任何操作之前等待很长时间)。
回答by Ognyan
I had similar issue with Win 7 + XAMPP. The problem was caused by the my antivirus software. When it was enabled even simplest PHP page was taking more than half a sec to open. Big PHP scripts with a lot of chained require_once()s tooked more than 1,5 seconds. With antivirus disabled everything was lightening fast (less than 100 miliseconds per simple pages, and about 500 miliseconds for really heavy stuff (100+ chained require_once())).
我在 Win 7 + XAMPP 上遇到了类似的问题。问题是由我的防病毒软件引起的。当它被启用时,即使是最简单的 PHP 页面也需要超过半秒才能打开。带有大量链式 require_once() 的大型 PHP 脚本耗时超过 1.5 秒。禁用防病毒软件后,一切都变快了(每个简单页面不到 100 毫秒,真正繁重的内容大约需要 500 毫秒(100 多个链接的 require_once()))。
I am using bitdeffender and here is the solution for it:
我正在使用 bitdefender,这是它的解决方案:
- Simple solution - just switch bitdefender to
game modewhen working with xampp - "Advanced" solution - go to
Antivirus -> Shield -> Advanced Settings -> Exclusions Taband there add exclusion for httpd.exe (located in your xampp installation/apache/bin/). Then go toAntivirus -> Exclusionsand add exclusion for the directory where your php files reside.
- 简单的解决方案 -
game mode使用 xampp 时只需将 bitdefender 切换到 - “高级”解决方案 - 转到
Antivirus -> Shield -> Advanced Settings -> Exclusions Tab并为 httpd.exe 添加排除项(位于您的 xampp 安装/apache/bin/)。然后转到Antivirus -> Exclusions并为您的 php 文件所在的目录添加排除项。
Don't forget to restart apache after above steps.
完成上述步骤后不要忘记重新启动apache。
Optionally you can install eaccelerator to speed the things even more.
您可以选择安装 eaccelerator 以加快速度。
As I side note: I found WAMP less mature as a project than XAMPP.
正如我的旁注:我发现 WAMP 作为一个项目不如 XAMPP 成熟。
Side note 2: The best solution is to use your old PC as linux server and everything will work like a charm :-)
旁注 2:最好的解决方案是将旧 PC 用作 linux 服务器,一切都会像魅力一样工作:-)
回答by Ronny Sherer
After reading several answers - non of them helped (I even removed my antivirus).
在阅读了几个答案之后 - 他们都没有帮助(我什至删除了我的防病毒软件)。
What helped me dramatically is disabling xdebug. Now everything became very fast.
对我有很大帮助的是禁用 xdebug。现在一切都变得非常快。
回答by Sanket Gupta
Two things can cause this issue.Anitivirus software and the settings in hostfile
有两个原因可能导致此问题。Anitivirus 软件和主机文件中的设置
1) in windows\system32\drivers\etc\hosts add the following lines:
1) 在 windows\system32\drivers\etc\hosts 添加以下几行:
127.0.0.1 127.0.0.1
127.0.0.1 127.0.0.1
127.0.0.1 localhost
127.0.0.1 本地主机
2) In your antivirus, exclude the document_root folder that contains your files (eg c:/www or c:/xampp/htdoc etc). To test this, you can also disable your anti virus temporarily but long term fix is to exclude the folder and subfolders
2) 在您的防病毒软件中,排除包含您的文件的 document_root 文件夹(例如 c:/www 或 c:/xampp/htdoc 等)。要对此进行测试,您还可以暂时禁用防病毒功能,但长期修复是排除文件夹和子文件夹
回答by Joe
My BUG - XAMPP VERY SLOW
我的错误 - XAMPP 非常慢
My Xampp slow down and eventual stop was caused by warnings messages filling the php log - read on
我的 Xampp 变慢并最终停止是由填充 php 日志的警告消息引起的 - 请继续阅读
1 - Localhost/127.0.0.1 - no help
1 - 本地主机/127.0.0.1 - 没有帮助
2 - Virus software interference - no help
2 - 病毒软件干扰 - 没有帮助
3 - Port interference changing to 8080 - no help
3 - 端口干扰更改为 8080 - 没有帮助
4 - Wamp - same thing - no help
4 - Wamp - 同样的事情 - 没有帮助
eventually things failed altogether with 500 errors.
最终事情完全失败了,出现了 500 个错误。
C:\xampp\php\logs\php_error_log was almost a MB (957K)
C:\xampp\php\logs\php_error_log 几乎是一个 MB (957K)
too big for notepadd++ (my first clue I was on to something) and notepad took several minutes to render.
对于记事本++来说太大了(我的第一个线索是我在做某事)并且记事本需要几分钟才能呈现。
Thousands of messages of the "Strict' & 'Warning' type
“严格”和“警告”类型的数千条消息
FIX
使固定
changed the php.ini display_errors=On to =Off "There are several other error on/off switches in there, but this one did it for me."
将 php.ini display_errors=On 更改为 =Off “那里还有其他几个错误开/关开关,但这个为我做了。”
nenamed log
命名日志
restarted apache and mysql
重新启动 apache 和 mysql
Life is good.
生活很好。
回答by ChelaTheGreat
Connecting to the DB using 127.0.0.1 instead of "localhost" worked for me.
使用 127.0.0.1 而不是“localhost”连接到数据库对我有用。
But i searched for another solution and came up with this:
但我搜索了另一种解决方案并提出了这个:
In your my.inifile, uncomment the following line:
在my.ini文件中,取消注释以下行:
# Change here for bind listening
# bind-address="127.0.0.1"
# bind-address = ::1 # for ipv6
You'll end up having:
你最终会得到:
# Change here for bind listening
bind-address="127.0.0.1"
# bind-address = ::1 # for ipv6
Restart your mysql server and pages should load very fast without the 2-3 second delay.
重新启动你的 mysql 服务器,页面加载速度应该很快,没有 2-3 秒的延迟。
Also, with this solution you don't need to modify your connection in your DB connect code, you can continue using "localhost" instead of "127.0.0.1"
此外,使用此解决方案,您无需在数据库连接代码中修改连接,您可以继续使用“localhost”而不是“127.0.0.1”
回答by VanAlbert
At the risk of stating the obvious -- check the size of your hosts file. My hosts file had ballooned to 450K due to Spybot adding exceptions for every malware site that ever existed even though those sites were mostly no longer active. Spybot commented these 10000+ entries with a copyright date of 2008, making them useless anyway.
冒着说明明显的风险 - 检查主机文件的大小。由于 Spybot 为曾经存在的每个恶意软件站点添加了例外,即使这些站点大部分不再活动,我的主机文件已经膨胀到 450K。Spybot 评论了这 10000 多个条目,版权日期为 2008 年,无论如何使它们毫无用处。
I don't know if other spyware protection software does this, but the hosts file should be small enough so that XAMPP doesn't have to churn through the exception URLs every time it displays a page. BTW if you have any cracked software installed, which I don't condone of course, be careful not to delete the hosts exceptions that block online validation checking sites.
我不知道其他间谍软件保护软件是否会这样做,但主机文件应该足够小,这样 XAMPP 就不必在每次显示页面时都翻阅异常 URL。顺便说一句,如果您安装了任何破解软件,我当然不会宽恕,请注意不要删除阻止在线验证检查站点的主机异常。
回答by Yada
How about giving Wamp Server a try?
试试 Wamp Server 怎么样?
The installation file is a lot smaller (16mb) compare to XAMPP (44mb).
与 XAMPP (44mb) 相比,安装文件要小得多 (16mb)。

