{"id":1454,"date":"2014-08-05T15:40:12","date_gmt":"2014-08-05T13:40:12","guid":{"rendered":"http:\/\/blog.gocept.com\/2014\/08\/05\/haproxy-load-balancing-for-php-applications-with-sticky-sessions\/"},"modified":"2014-08-05T15:53:22","modified_gmt":"2014-08-05T13:53:22","slug":"haproxy-load-balancing-for-php-applications-with-sticky-sessions","status":"publish","type":"post","link":"https:\/\/blog.gocept.com\/2014\/08\/05\/haproxy-load-balancing-for-php-applications-with-sticky-sessions\/","title":{"rendered":"haproxy load-balancing for PHP applications with sticky sessions"},"content":{"rendered":"

We like\u00a0applications\u00a0that are\u00a0written\u00a0with a\u00a0shared-nothing<\/a>\u00a0approach: it\u00a0greatly simplifies running multiple instances on multiple hosts and allows for simple, robust load-balancer configuration.<\/p>\n

Recently, we had to deploy a PHP application that – in the last minute – turned out to use PHP sessions and\u00a0thus required sticky sessions.<\/p>\n

We haven’t used sticky sessions in a while\u00a0and the amount of reading required to find the specific working setup was substantial, so we’ll repeat here what a post at\u00a0networkinghowtos.com<\/a>\u00a0already figured out:<\/p>\n

backend default
\u00a0 \u00a0 appsession PHPSESSID len 64 timeout 3h request-learn prefix<\/code><\/p>\n

As you can see there isn’t much magic to it – the haproxy manual has a good in-detail explanation of the\u00a0appsession option<\/a>. The biggest point of this option is that you do not have haproxy injecting another session identifier but simply piggybacks on the existing one that PHP determines. Also, this option combines nicely with “leastconn” balancing if your application\u00a0only uses cookies on a few selected pages and many users do not\u00a0trigger getting a session cookie.<\/p>\n","protected":false},"excerpt":{"rendered":"

We like\u00a0applications\u00a0that are\u00a0written\u00a0with a\u00a0shared-nothing\u00a0approach: it\u00a0greatly simplifies running multiple instances on multiple hosts and allows for simple, robust load-balancer configuration. Recently, we had to deploy a PHP application that – in the last minute – turned out to use PHP sessions and\u00a0thus required sticky sessions. We haven’t used sticky sessions in a while\u00a0and the amount of … Continue reading “haproxy load-balancing for PHP applications with sticky sessions”<\/span><\/a><\/p>\n","protected":false},"author":12391367,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_newsletter_tier_id":0,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[1],"tags":[],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pFP3y-ns","jetpack-related-posts":[{"id":179,"url":"https:\/\/blog.gocept.com\/2012\/05\/28\/sprint-report-deploying-python-web-applications-platforms-and-applications\/","url_meta":{"origin":1454,"position":0},"title":"Sprint report: Deploying Python web applications – platforms and applications","author":"Daniel Havlik","date":"May 28, 2012","format":false,"excerpt":"Last week I met Stephan Diehl, Michael Hierweck, Veit Schiele, and Jens Vagelpohl\u00a0in Berlin for a sprint. Our chosen topic was \"Python web application\u00a0deployment\". In this post I'd like to recap our discussions, gocept's perspective on those, and the deployment tool \"batou\" that we have been incubating in the last\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1437,"url":"https:\/\/blog.gocept.com\/2014\/07\/03\/follow-up-actions-after-the-filesystem-corruption-incident\/","url_meta":{"origin":1454,"position":1},"title":"Follow up actions after the filesystem corruption incident","author":"","date":"July 3, 2014","format":false,"excerpt":"On 2014-06-07, the Flying Circus experienced a quite unfortunate filesystem corruption\u00a0incident. Most of the VMs have been cleaned up since then, but a few defective files are still around. In the following article, I'll provide some background information on what types of corruption we saw, what you (as our customer)\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":171,"url":"https:\/\/blog.gocept.com\/2012\/05\/22\/dont-stop-postgresqls-autovacuum-with-your-application\/","url_meta":{"origin":1454,"position":2},"title":"Don’t stop PostgreSQL’s autovacuum with your application","author":"","date":"May 22, 2012","format":false,"excerpt":"The problem Some weeks ago, we received a complaint from a customer about bad PostgreSQL performance for a specific application. I took a look into the database and found strange things going on: the query planner was executing \"interesting\" query plans, tables were bloated with lots of dead rows (one\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1332,"url":"https:\/\/blog.gocept.com\/2013\/07\/15\/reliable-file-updates-with-python\/","url_meta":{"origin":1454,"position":3},"title":"Reliable file updates with Python","author":"","date":"July 15, 2013","format":false,"excerpt":"Programs need to update files. Although most programmers know that unexpected things can happen while performing I\/O, I often see code that has been written in a surprisingly na\u00efve way. In this article, I would like to share some insights on how to improve I\/O reliability in Python code. Consider\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3229,"url":"https:\/\/blog.gocept.com\/2018\/06\/07\/migrate-a-zope-zodb-data-fs-to-python-3\/","url_meta":{"origin":1454,"position":4},"title":"Migrate a Zope ZODB Data.fs to Python 3","author":"Michael Howitz","date":"June 7, 2018","format":false,"excerpt":"TL;DR Use\u00a0zodbupdate. Problem A ZODB\u00a0Data.fs\u00a0which was created under Python 2 cannot be opened under Python 3. This is prevented by using a different magic code in the first bytes of the file. This is done on purpose because str\u00a0has a different meaning for the two Python versions: Under Python 2\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2018\/06\/spring-3383890_1280.jpg?fit=1200%2C797&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2018\/06\/spring-3383890_1280.jpg?fit=1200%2C797&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2018\/06\/spring-3383890_1280.jpg?fit=1200%2C797&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2018\/06\/spring-3383890_1280.jpg?fit=1200%2C797&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/blog.gocept.com\/wp-content\/uploads\/2018\/06\/spring-3383890_1280.jpg?fit=1200%2C797&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":1276,"url":"https:\/\/blog.gocept.com\/2013\/05\/02\/developer-admin-bbq-iv-2\/","url_meta":{"origin":1454,"position":5},"title":"developer & admin BBQ IV","author":"","date":"May 2, 2013","format":false,"excerpt":"Our fourth BBQ (invitation post) had the most participants so far, almost 20 people were here to talk shop, exchange ideas and brave the unfortunately slightly rainy weather (the grilled goods were delicious regardless). We're especially glad that the ratio of gocept people to guests was only about 50% this\u2026","rel":"","context":"In "en"","block_context":{"text":"en","link":"https:\/\/blog.gocept.com\/category\/en\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/1454"}],"collection":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/users\/12391367"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/comments?post=1454"}],"version-history":[{"count":4,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/1454\/revisions"}],"predecessor-version":[{"id":1458,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/posts\/1454\/revisions\/1458"}],"wp:attachment":[{"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/media?parent=1454"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/categories?post=1454"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gocept.com\/wp-json\/wp\/v2\/tags?post=1454"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}