Reputation: 892
I'm trying to make atomic deploys with Nginx and PHP5.5-FPM with Opcache.
The idea is just to change the webroot in nginx.conf and then just run
nginx reload
What I'm expecting is that Nginx will wait for the current requests to end and then reload itself passing the new webroot path to PHP FPM, but it's not working: PHP FPM is still loading the PHP files from the old directory. I'm using the (undocumented) $realpath_root in Ngnix in order not to get the symlink (/prod/current) but the real path. The technique is documented here: http://codeascraft.com/2013/07/01/atomic-deploys-at-etsy/ Debugging Nginx I can clearly see that it is passing the new(real) path.
2014/09/23 17:13:22 [debug] 26234#0: *1742 http script var: "/www/htdocs/current/web"
2014/09/23 17:13:22 [debug] 26234#0: *1742 posix_memalign: 00000000010517A0:4096 @16
2014/09/23 17:13:22 [debug] 26234#0: *1742 http script copy: "SCRIPT_FILENAME"
2014/09/23 17:13:22 [debug] 26234#0: *1742 http script var: "/www/htdocs/prod/releases/20140923124417/web"
2014/09/23 17:13:22 [debug] 26234#0: *1742 http script var: "/index.php"
2014/09/23 17:13:22 [debug] 26234#0: *1742 fastcgi param: "SCRIPT_FILENAME: /www/htdocs/prod/releases/20140923124417/web/app.php"
2014/09/23 17:13:22 [debug] 26234#0: *1742 http script copy: "DOCUMENT_ROOT"
2014/09/23 17:13:22 [debug] 26234#0: *1742 http script var: "/www/htdocs/prod/releases/20140923124417/web"
2014/09/23 17:13:22 [debug] 26234#0: *1742 fastcgi param: "DOCUMENT_ROOT: /www/htdocs/prod/releases/20140923124417/web"
2014/09/23 17:13:22 [debug] 26234#0: *1742 http script copy: "APPLICATION_ENV"
To make it work I have to run a
php-fpm reload
but I'm loosing some requests.
'recv() failed (104: Connection reset by peer) while reading response header from upstream'
This is the nginx file I'm using:
server {
listen 26023;
server_name prod.example.com;
client_max_body_size 20m;
client_header_timeout 1200;
client_body_timeout 1200;
send_timeout 1200;
keepalive_timeout 1200;
access_log /var/logs/prod/nginx/prod.access.log main;
error_log /var/logs/prod/nginx/prod.error.log;
set $root_location /var/www/htdocs/prod/current/web;
root $root_location;
try_files $uri $uri/ /index.php?$args;
index index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php5-fpm/prod.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_connect_timeout 1200;
fastcgi_send_timeout 1200;
fastcgi_read_timeout 1200;
fastcgi_ignore_client_abort on;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param APPLICATION_ENV live;
fastcgi_param HTTPS $thttps;
}
}
this is the pool conf:
:~$ curl http://127.0.0.1/fpm_status_prod
pool: prod
process manager: dynamic
start time: 23/Sep/2014:22:42:34 +0400
start since: 1672
accepted conn: 446
listen queue: 0
max listen queue: 0
listen queue len: 0
idle processes: 49
active processes: 1
total processes: 50
max active processes: 2
max children reached: 0
slow requests: 0
Any suggestion?
Upvotes: 0
Views: 929
Reputation: 892
I fixed the issue, I was also using APC for the classloader and it wasn't cleared.
Upvotes: 1