{"id":246,"date":"2015-11-13T09:07:23","date_gmt":"2015-11-13T14:07:23","guid":{"rendered":"http:\/\/jamesroberts.name\/blog\/?p=246"},"modified":"2015-11-13T09:22:27","modified_gmt":"2015-11-13T14:22:27","slug":"opcache-issues-resolved-for-symlink-based-atomic-deploys-and-php-fpm","status":"publish","type":"post","link":"https:\/\/jamesroberts.name\/blog\/2015\/11\/13\/opcache-issues-resolved-for-symlink-based-atomic-deploys-and-php-fpm\/","title":{"rendered":"Opcache issues resolved for symlink based atomic deploys and PHP-FPM"},"content":{"rendered":"<p>I recently ran into problems with php-fpm and opcache using symbolic links for atomic deploys.  The solution was so simple, use <code>$realpath_root<\/code> instead of <code>$document_root<\/code> in your fastcgi config.  Thank you nginx, you make me feel all warm and fuzzy inside.<\/p>\n<pre lang=\"bash\">\r\nfastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;\r\nfastcgi_param DOCUMENT_ROOT $realpath_root;\r\n<\/pre>\n<p>Details below &#8212;<\/p>\n<p>Folder structure:<\/p>\n<pre>\r\n\u251c\u2500\u2500 current -> deploy1\r\n\u251c\u2500\u2500 deploy1\r\n\u2502   \u2514\u2500\u2500 www\/index.php\r\n\u2514\u2500\u2500 deploy2\r\n    \u2514\u2500\u2500 www\/index.php\r\n<\/pre>\n<p>The problem:<\/p>\n<p>Opcache does not use filesystem inodes when it saves file paths.  What this means is when you flip the &#8220;current&#8221; symlink from &#8220;deploy1&#8221; to &#8220;deploy2&#8221;, the opcache thinks php-fpm requests are still referencing <code>deploy1\/www\/index.php<\/code> because the file path it has saved is <code>current\/www\/index.php<\/code> rather than the &#8220;real&#8221; file path.<\/p>\n<p>The solution:<\/p>\n<p>Have nginx to resolve the symbolic link before the request even gets to php-fpm:<\/p>\n<pre lang=\"bash\">\r\nfastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;\r\nfastcgi_param DOCUMENT_ROOT $realpath_root;\r\n<\/pre>\n<p>Full disclosure, I found the above solution here: http:\/\/stackoverflow.com\/a\/23904770<\/p>\n<p>I still recommend that you clear Opcache after doing a deploy and flipping the symlink, but this solution does not require you to do that.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently ran into problems with php-fpm and opcache using symbolic links for atomic deploys. The solution was so simple, use $realpath_root instead of $document_root in your fastcgi config. Thank you nginx, you make me feel all warm and fuzzy inside. fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $realpath_root; Details below &#8212; Folder structure: \u251c\u2500\u2500 current -> [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[47,68,46],"_links":{"self":[{"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/posts\/246"}],"collection":[{"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/comments?post=246"}],"version-history":[{"count":4,"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/posts\/246\/revisions"}],"predecessor-version":[{"id":250,"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/posts\/246\/revisions\/250"}],"wp:attachment":[{"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/media?parent=246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/categories?post=246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jamesroberts.name\/blog\/wp-json\/wp\/v2\/tags?post=246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}