我在运行ML的MacBook上用PHP-FPM设置了Nginx.它工作正常但我在浏览器中运行页面时需要5到10秒才能连接.甚至以下PHP脚本:
<?php
die();
Run Code Online (Sandbox Code Playgroud)
大约需要5秒钟才能连接.我正在使用Chrome,我在状态栏中收到"发送请求"消息大约7秒钟.如果我再次刷新它似乎立即工作,但如果我离开它大约10秒钟它将再次"睡觉".就好像nginx或PHP会睡觉然后再花几年时间再醒来.
编辑:这也影响服务器上的静态文件,因此它似乎是DNS或nginx的问题.
任何人都可以帮我找出造成这种情况的原因吗?
nginx.conf
worker_processes 2;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type text/plain;
server_tokens off;
sendfile on;
tcp_nopush on;
keepalive_timeout 1;
gzip on;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/css text/javascript application/json application/x-javascript text/xml application/xml application/xml+rss;
index index.html index.php;
upstream www-upstream-pool{
server unix:/tmp/php-fpm.sock;
}
include sites-enabled/*;
}
Run Code Online (Sandbox Code Playgroud)
PHP-fpm.conf
[global]
pid = /usr/local/etc/php/var/run/php-fpm.pid
; run in background or in foreground?
; set daemonize = no for debugging
daemonize = yes
include=/usr/local/etc/php/5.4/pool.d/*.conf
Run Code Online (Sandbox Code Playgroud)
pool.conf …
我想从数据库的行数组中构建一个哈希.我可以使用下面的代码轻松完成.我从PHP来到Ruby,这就是我要做的.在Ruby(或Rails)中有更好/正确的方法吗?
def features_hash
features_hash = {}
product_features.each do |feature|
features_hash[feature.feature_id] = feature.value
end
features_hash
end
# {1 => 'Blue', 2 => 'Medium', 3 => 'Metal'}
Run Code Online (Sandbox Code Playgroud)