php窗口比linux慢4〜5倍

我有一个站点部署到Windows Server 2012和Ubuntu 14.04,有一个显着的性能差异。 代码库和DB数据完全一样。

Windows环境

  1. AWS EC2中的Windows Server 2012 t2.medium(双核4GB RAM)
  2. PHP 5.5 64位ts
  3. Apache 2.4.23

Linux的

  1. AWS EC2 t2.medium中的Ubuntu 14.04(双核4GB RAM)
  2. PHP 5.5 64位ts
  3. Apache 2.4

这两个站点都启用了OpCache。

执行时间(唯一的PHP执行时间,不包括所有的networkingstream量)

  • Windows:2.6-2.8s
  • Linux:200-400ms

在Windows中,我们注意到在单页加载时,几乎有100%的CPU负载峰值和3-4MB的IO读取峰值。

我已经在Windows上看到了有关PHP性能的Stackoverflow中的各种post,但是我们已经从那些post应用/testing了build议到没有avil

  • https://stackoverflow.com/questions/22845321/php-factor-30-performance-difference-from-linux-to-windows
  • https://stackoverflow.com/questions/9854848/windows-7-php-symfony2-terribly-slow

任何意见,将不胜感激!

最后给我自己一个答案

性能差异是由于php函数is_dir()在Window中performance糟糕

Test1:运行简单脚本循环1000次,调用is_dir()

  • Windows:217ms
  • Mac:8ms

Test2:使用xdebug和is_dir()对代码进行剖析以获得最高执行时间

其他一些参考文献也指出了同样的问题https://github.com/facebook/hhvm/issues/4431

希望这篇文章可以帮助他人面对同样的问题