每天PHP-FPM超时问题

我使用nginx,PHP-FPM,MySQL运行一个专用的服务器,并且运行了几个站点,但是我每天都有超时问题,几乎每24小时都会运行WordPress。

PHP-FPM错误:

[14-Jan-2012 04:00:48] WARNING: [pool www] child 2759, script '/home/fez/www/index.php' (request: "GET /index.php") execution timed out (73.614398 sec), terminating [14-Jan-2012 04:00:48] WARNING: [pool www] child 2759 exited on signal 15 (SIGTERM) after 114278.396462 seconds from start 

nginx错误:

 2012/01/14 04:00:48 [error] 1629#0: *859825 upstream timed out (110: Connection timed out) while reading upstream, client: 82.130.40.76, server: www.flesheatingzipper.com, request: "GET /gaming/2011/11/skyrim-guide-dragon-shout-rune-locations-youre-welcome/ HTTP/1.1", upstream: "fastcgi://unix:/tmp/php5-fpm.sock:", host: "www.flesheatingzipper.com" 

WordPress crons:

  • jetpack_clean_nonces – 每小时
  • akismet_scheduled_delete – 每日凌晨3:00
  • wp_version_check – 每天两次(上午10点到晚上10点)
  • wp_update_plugins – 每天两次(上午10点到晚上10点)
  • wp_update_themes – 每天两次(上午10点到晚上10点)
  • wp_scheduled_delete – 每日@ 10am

这是我的PHP-FPMconfiguration: http : //pastebin.com/ppsWeHVN

WordPress的cron作业奇怪的事情。 它有一个wp-cron.php文件,可以在页面请求中被包含/执行。 这是用来模拟crontab的人谁不能访问一个真正的crontab。

我怀疑你已经在你的WordPresspipe理中心configuration了一个日常的cron工作,这个工作需要超过73秒。 最后一次运行24小时后的第一个页面请求将再次触发该cron作业,并导致另一个超时。

至于为什么它最终成功,我只能猜测,要么是在每次运行中完成部分工作并保存其进度,要么是操作系统caching越来越多的文件,直到它可以获得整体cron的工作做得比超时还快。

有些人已经通过普通的crontab来使WordPress cron作业工作 。

akismet_scheduled_delete - Daily @ 3:00am cron作业看起来像是最有可能的罪魁祸首。 服务器和PHP的当前时区视图之间是有区别的,这意味着凌晨3点的工作实际上在凌晨4点运行,或者工作需要一个多小时才能执行。

它看起来像是与Wassup插件相关的。 我启用PHP缓慢的日志,并收到以下错误后,网站再次坠毁,但在白天。 在停用插件之后,网站立刻变得更快,并且没有像之前那样缓慢起伏。

 [25-Jan-2012 15:09:20] [pool www] pid 3593 script_filename = /home/fez/www/index.php [0x00007f353cb75890] mysql_query() /home/fez/www/wp-includes/wp-db.php:1091 [0x00007f353cb75670] query() /home/fez/www/wp-includes/wp-db.php:1375 [0x00007f353cb753d8] get_results() /home/fez/www/wp-content/plugins/wassup/lib/wassup.class.php:553 [0x00007f353cb75278] getMySQLsetting() /home/fez/www/wp-content/plugins/wassup/lib/wassup.class.php:180 [0x00007f353cb750c0] defaultSettings() /home/fez/www/wp-content/plugins/wassup/lib/wassup.class.php:232 [0x00007f353cb74fc0] getSettings() /home/fez/www/wp-content/plugins/wassup/lib/wassup.class.php:212 [0x00007f353cb74ef8] loadSettings() /home/fez/www/wp-content/plugins/wassup/lib/wassup.class.php:90 [0x00007f353cb74b10] wassupoptions() /home/fez/www/wp-content/plugins/wassup/wassup.php:1822 [0x00007f353cb749d0] wassupPrepend() /home/fez/www/wp-content/plugins/wassup/wassup.php:326 [0x00007fff788d6280] wassup_init() unknown:0 [0x00007f353cb747a8] call_user_func_array() /home/fez/www/wp-includes/plugin.php:405 [0x00007f353cb74410] do_action() /home/fez/www/wp-settings.php:304 [0x00007f353cb74320] +++ dump failed 

你从来没有给你的nginxconfiguration。 但是,PHP-FPM儿童的SIGTERM(15)可以是下列之一:

  • 打开文件描述符太低(编辑/etc/security/limits.conf并为您的Web用户创build一个条目,并将'nofiles'设置为更高的值)。 如果你使用的话,也可以在你的PHP-FPMconfiguration中将rlimit_files设置为更高的值

  • 你在你的nginxconfiguration中使用fastcgi_keep_conn。 这在php-fpm中带有'ondemand'和'dynamic'的configuration会导致灾难性的结果,因为php-fpm会断开连接并build立新的php-fpm子项,但是nginx不知道如何重新连接,所以你的站点将会崩溃。

我猜你有一个数据库转储或备份运行,一些表被locking在它的过程中,总是使一些不错的超时。 尝试启用mysql的慢查询日志,并检查周四凌晨查询缓慢。