# Latency problem with one browser

**URL:** <https://www.ruby-forum.com/t/latency-problem-with-one-browser/217475>\
**Category:** NGINX\
**Created:** [March 2, 2012, 1:39pm UTC](https://www.ruby-forum.com/t/latency-problem-with-one-browser/217475 "2012-03-02T13:39:31Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 2, 2012, 1:39pm UTC](https://www.ruby-forum.com/t/latency-problem-with-one-browser/217475/1 "2012-03-02T13:39:31Z")

</div>

Hi,

I installed nginx 1.05 and php-fpm 5.3.10 in Ubuntu 11.10.

If I browse with explorer,firefox and chrome all works very well, all is  
fast!

If I use my Playbook (with webkit) all is slow! With webinspector I  
noticed that the problem is latency. I get a very high latency (from 3  
to 15 seconds random) for all the pages with php code.

With the same playbook, I browse the SAME SITES inside other server  
(actually I’ve just copied it in it ):

```
  - nginx 0.84
  - php 5.3.0
  - ubuntu 9.10

```

and works very well and fast! It’s incredible!

I have attached the main nginx.conf, nginx-vs.conf, main php-fpm.conf,  
php-fpm-vs.conf and fastcgi\_params\_phpfpm.

Any idea?

Thanks a lot,

Andrea

---

<div class="post-metadata">

**Author:** ![ascarp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@ascarp](https://www.ruby-forum.com/u/ascarp)\
**Post date:** [March 2, 2012, 2:09pm UTC](https://www.ruby-forum.com/t/latency-problem-with-one-browser/217475/2 "2012-03-02T14:09:57Z")

</div>

Hello!

On Fri, Mar 02, 2012 at 01:38:45PM +0100, Andrea S. wrote:

> ```
> - nginx 0.84
> - php 5.3.0
> - ubuntu 9.10
> 
> ```
> 
> and works very well and fast! It’s incredible!
> 
> I have attached the main nginx.conf, nginx-vs.conf, main php-fpm.conf,  
> php-fpm-vs.conf and fastcgi\_params\_phpfpm.
> 
> Any idea?

Try

```
keepalive_disable msie6;

```

> **[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_disable)**
>
> This directive appeared in version 1.11.8.

Maxim D.

---

<div class="post-metadata">

**Author:** ![ascarp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@ascarp](https://www.ruby-forum.com/u/ascarp)\
**Post date:** [March 2, 2012, 2:16pm UTC](https://www.ruby-forum.com/t/latency-problem-with-one-browser/217475/3 "2012-03-02T14:16:48Z")

</div>

02 марта 2012, 17:09 от Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > 
> 
> [Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_disable)

This is WebKit related, so this is more likely to help:

keepalive\_disable safari;

Max

---

<div class="post-metadata">

**Author:** ![ascarp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@ascarp](https://www.ruby-forum.com/u/ascarp)\
**Post date:** [March 2, 2012, 2:52pm UTC](https://www.ruby-forum.com/t/latency-problem-with-one-browser/217475/4 "2012-03-02T14:52:06Z")

</div>

Hello!

On Fri, Mar 02, 2012 at 05:15:54PM +0400, Max wrote:

> > > If I browse with explorer,firefox and chrome all works very well, all is  
> > > - php 5.3.0
> > 
> > keepalive\_disable msie6;
> > 
> > [Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_disable)
> 
> This is WebKit related, so this is more likely to help:
> 
> keepalive\_disable safari;

No. The problem is that keepalive is disabled by default for safari,  
and the “keepalive\_disable msie6;” will re-enable it.

Maxim D.

---

<div class="post-metadata">

**Author:** ![ascarp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@ascarp](https://www.ruby-forum.com/u/ascarp)\
**Post date:** [March 2, 2012, 4:53pm UTC](https://www.ruby-forum.com/t/latency-problem-with-one-browser/217475/5 "2012-03-02T16:53:42Z")

</div>

Yes,

with “keepalive\_disable none;” works fine!

Thanks a lot,  
Andrea

----- Messaggio originale -----  
Da: “Maxim D.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
A: [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Inviato: Venerdì, 2 marzo 2012 14:51:46  
Oggetto: Re: Latency problem with one browser

Hello!

On Fri, Mar 02, 2012 at 05:15:54PM +0400, Max wrote:

> > > If I browse with explorer,firefox and chrome all works very well, all is  
> > > - php 5.3.0
> > 
> > keepalive\_disable msie6;
> > 
> > [Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_disable)
> 
> This is WebKit related, so this is more likely to help:
> 
> keepalive\_disable safari;

No. The problem is that keepalive is disabled by default for safari,  
and the “keepalive\_disable msie6;” will re-enable it.

Maxim D.

* * *

nginx mailing list  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> **[mailman.nginx.org archive](http://mailman.nginx.org/pipermail/)**

---

<div class="post-metadata">

**Author:** ![ascarp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@ascarp](https://www.ruby-forum.com/u/ascarp)\
**Post date:** [March 2, 2012, 5:35pm UTC](https://www.ruby-forum.com/t/latency-problem-with-one-browser/217475/6 "2012-03-02T17:35:03Z")

</div>

Hi,

> This disables keepalive for safari and browser “none”,
> 
> I know this directive is a workaround in the first place, but it would  
> be nice if this were documented in the official documentation.

It is:

> **[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_disable)**
>
> This directive appeared in version 1.11.8.

Best regards,  
Piotr S. \< [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) \>

---

<div class="post-metadata">

**Author:** ![ascarp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@ascarp](https://www.ruby-forum.com/u/ascarp)\
**Post date:** [March 2, 2012, 5:29pm UTC](https://www.ruby-forum.com/t/latency-problem-with-one-browser/217475/7 "2012-03-02T17:29:22Z")

</div>

02 марта 2012, 17:52 от Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > > > Hi,  
> > > > With the same playbook, I browse the SAME SITES inside other server
> > 
> > keepalive\_disable safari;
> 
> No. The problem is that keepalive is disabled by default for safari,  
> and the “keepalive\_disable msie6;” will re-enable it.

Just for the record - keepalive\_disable is set to msie6 and safari  
by default, but using the keepalive\_disable directive explicitly  
disables keepalive for the specified arguments and implicitly  
enables (by not disabling) keepalive for all the other possible  
arguments.

So to enable keepalive for a browser that has keepalive disabled  
by default (which currently includes msie6 and safari) you have  
to use “keepalive\_disable ID;”, where ID is anything but the ID  
of the browser you want to enable keepalive for.

This disables keepalive for msie6 and implicitly enables  
keepalive for safari and all the other browsers:

keepalive\_disable msie6;

This disables keepalive for safari and implicitly enables  
keepalive for msie6 and all the other browsers:

keepalive\_disable safari;

This disables keepalive for safari and browser “none”,  
and implicitly enables keepalive for msie6, but not  
due to the “none” argument:

keepalive\_disable none safari;

That’s because “none” does not actually reset the keepalive\_disable  
variable to zero, it’s implemented as another browser (2nd bit in the  
keepalive\_disable browser bitmap), so specifying “none” as a single  
argument disables keepalive only for browser “none” and implicitly  
enables it for all the other browsers.

I know this directive is a workaround in the first place, but it would  
be nice if this were documented in the official documentation.

Max

---

<div class="post-metadata">

**Author:** ![ascarp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@ascarp](https://www.ruby-forum.com/u/ascarp)\
**Post date:** [March 2, 2012, 5:49pm UTC](https://www.ruby-forum.com/t/latency-problem-with-one-browser/217475/8 "2012-03-02T17:49:25Z")

</div>

02 марта 2012, 19:53 от Andrea S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Yes,
> 
> with “keepalive\_disable none;” works fine!

Maxim, do you think the Playbook browser should be added as a  
separate browser (unsigned playbook:1 entry in ngx\_http\_headers\_in\_t)  
to prevent it from getting the Safari keepalive disabled treatment?

Here’s a typical Playbook browser User-Agent string, adding an if  
block for “Playbook” before the “Safari” if block in  
ngx\_http\_process\_user\_agent() should do the trick:

Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US)   
AppleWebKit/534.8+ (KHTML like Gecko) version/0.0.1 Safari/534.8+

Max

---

<div class="post-metadata">

**Author:** ![ascarp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@ascarp](https://www.ruby-forum.com/u/ascarp)\
**Post date:** [March 4, 2012, 1:58pm UTC](https://www.ruby-forum.com/t/latency-problem-with-one-browser/217475/9 "2012-03-04T13:58:54Z")

</div>

Hello!

On Fri, Mar 02, 2012 at 08:48:43PM +0400, Max wrote:

> Here’s a typical Playbook browser User-Agent string, adding an if  
> block for “Playbook” before the “Safari” if block in  
> ngx\_http\_process\_user\_agent() should do the trick:
> 
> Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US)   
> AppleWebKit/534.8+ (KHTML like Gecko) version/0.0.1 Safari/534.8+

Detecting all browsers (thousands of them) which pretend to be  
Safari is not an option. And, after all, browsers use other’s  
product token for reason, and workarounds for bugs is what they  
expect to get as a result.

I’m planning to disable this Safari workaround by default instead,  
the following patch is already sitting in my queue:

# HG changeset patch

# User Maxim D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

# Date 1330697796 -14400

# Node ID 88e257b4bd3d61e30d1421ab6f2e417a8baedb96

# Parent 277a1822fc5cf7ad83297c74839ca8c84a49680c

Removed safari from keepalive\_disable default.

The bug in question is likely already fixed (though unfortunately we  
have  
no information available as Apple’s bugtracker isn’t open), and the  
workaround seems to be too pessimistic for modern versions of Safari  
as well as other webkit-based browsers pretending to be Safari.

diff --git a/src/http/ngx\_http\_core\_module.c  
b/src/http/ngx\_http\_core\_module.c  
— a/src/http/ngx\_http\_core\_module.c  
+++ b/src/http/ngx\_http\_core\_module.c  
@@ -3568,8 +3568,7 @@ ngx\_http\_core\_merge\_loc\_conf(ngx\_conf\_t  
ngx\_conf\_merge\_bitmask\_value(conf-\>keepalive\_disable,  
prev-\>keepalive\_disable,  
(NGX\_CONF\_BITMASK\_SET

- 

```
                          |NGX_HTTP_KEEPALIVE_DISABLE_MSIE6

```

- 

```
                          |NGX_HTTP_KEEPALIVE_DISABLE_SAFARI));

```

- 

```
                          |NGX_HTTP_KEEPALIVE_DISABLE_MSIE6));

```

ngx\_conf\_merge\_uint\_value(conf-\>satisfy, prev-\>satisfy,  
NGX\_HTTP\_SATISFY\_ALL);  
ngx\_conf\_merge\_uint\_value(conf-\>if\_modified\_since,  
prev-\>if\_modified\_since,

Maxim D.

---

<div class="post-metadata">

**Author:** ![ascarp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@ascarp](https://www.ruby-forum.com/u/ascarp)\
**Post date:** [March 4, 2012, 2:40pm UTC](https://www.ruby-forum.com/t/latency-problem-with-one-browser/217475/10 "2012-03-04T14:40:25Z")

</div>

Hi Maxim,

> > Mozilla/5.0 (PlayBook; U; RIM Tablet OS 1.0.0; en-US)   
> > AppleWebKit/534.8+ (KHTML like Gecko) version/0.0.1 Safari/534.8+
> 
> Detecting all browsers (thousands of them) which pretend to be  
> Safari is not an option. And, after all, browsers use other’s  
> product token for reason, and workarounds for bugs is what they  
> expect to get as a result.

Except that PlayBook isn’t a browser, it’s a device 😉

> The bug in question is likely already fixed (though unfortunately we have  
> (NGX\_CONF\_BITMASK\_SET
> 
> - 
> 
> ```
> |NGX_HTTP_KEEPALIVE_DISABLE_MSIE6
> 
> ```
> 
> - 
> 
> ```
> |NGX_HTTP_KEEPALIVE_DISABLE_SAFARI));
> 
> ```
> 
> - 
> 
> ```
> |NGX_HTTP_KEEPALIVE_DISABLE_MSIE6));
> 
> ```
> 
> ngx\_conf\_merge\_uint\_value(conf-\>satisfy, prev-\>satisfy,  
> NGX\_HTTP\_SATISFY\_ALL);  
> ngx\_conf\_merge\_uint\_value(conf-\>if\_modified\_since, prev-\>if\_modified\_since,

I don’t really agree with this, it’s analogues to removing IE  
work-around  
instead of restricting it to versions older than IE6 SV1. I was looking  
at  
this issue over the weekend and the “keepalive\_disable safari” option is  
simply too broad and that’s what needs to be fixed.

According to [5760 – Safari hangs when uploading files to certain php scripts](https://bugs.webkit.org/show_bug.cgi?id=5760#c38),  
the underlying issue was in the Foundation framework on iOS/OSX, not  
Safari,  
which means that Safari on Windows as well as everything else (Android,  
BlackBerry, etc.) that uses WebKit was never affected.

I agree with you and I believe that it’s fixed in the most recent  
releases  
of iOS/OSX, but I wouldn’t bet that it’s fixed in iOS 4.x, OSX 10.6.x or  
older releases, so why should we disable the work-around for them?

Best regards,  
Piotr S. \< [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) \>

---

<div class="post-metadata">

**Author:** ![ascarp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@ascarp](https://www.ruby-forum.com/u/ascarp)\
**Post date:** [March 4, 2012, 6:41pm UTC](https://www.ruby-forum.com/t/latency-problem-with-one-browser/217475/11 "2012-03-04T18:41:20Z")

</div>

Hello!

On Sun, Mar 04, 2012 at 02:39:53PM +0100, Piotr S. wrote:

> Except that PlayBook isn’t a browser, it’s a device 😉
> 
> > ```
> > prev->keepalive_disable,
> > 
> > ```
> 
> this issue over the weekend and the “keepalive\_disable safari” option is  
> simply too broad and that’s what needs to be fixed.
> 
> According to [5760 – Safari hangs when uploading files to certain php scripts](https://bugs.webkit.org/show_bug.cgi?id=5760#c38),  
> the underlying issue was in the Foundation framework on iOS/OSX, not Safari,  
> which means that Safari on Windows as well as everything else (Android,  
> BlackBerry, etc.) that uses WebKit was never affected.
> 
> I agree with you and I believe that it’s fixed in the most recent releases  
> of iOS/OSX, but I wouldn’t bet that it’s fixed in iOS 4.x, OSX 10.6.x or  
> older releases, so why should we disable the work-around for them?

I believe that the workaround is too pessimistic even for affected  
versions as it disables keepalive completely, while the problem  
will only manifest itself if there are POSTs.

If someone will find itself affected and the cost of disabled  
keepalive is acceptable - it will be still possible to explicitly  
enable the workaround.

Restricting the workaround to something like “Safari on Mac OS X”  
would be fine too, though it’s mostly orthogonal to changing the  
default.

Maxim D.

---

<div class="post-metadata">

**Author:** ![ascarp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@ascarp](https://www.ruby-forum.com/u/ascarp)\
**Post date:** [March 4, 2012, 9:36pm UTC](https://www.ruby-forum.com/t/latency-problem-with-one-browser/217475/12 "2012-03-04T21:36:06Z")

</div>

Hi Maxim,

> I believe that the workaround is too pessimistic even for affected  
> versions as it disables keepalive completely, while the problem  
> will only manifest itself if there are POSTs.
> 
> If someone will find itself affected and the cost of disabled  
> keepalive is acceptable - it will be still possible to explicitly  
> enable the workaround.

I’m aware of this and I still respectfully disagree with you, because  
changing the default is basically trading correctness for performance.

> Restricting the workaround to something like “Safari on Mac OS X”  
> would be fine too, though it’s mostly orthogonal to changing the  
> default.

Agreed, but it makes changing the default much less appealing.

Best regards,  
Piotr S. \< [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) \>

---

<div class="post-metadata">

**Author:** ![ascarp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@ascarp](https://www.ruby-forum.com/u/ascarp)\
**Post date:** [March 15, 2012, 7:43pm UTC](https://www.ruby-forum.com/t/latency-problem-with-one-browser/217475/13 "2012-03-15T19:43:40Z")

</div>

Hello!

On Sun, Mar 04, 2012 at 10:08:45PM +0100, Piotr S. wrote:

> - Mozilla/5.0 (iPad; CPU OS 5\_0\_1 like Mac OS X) …
> 
> - 
> 
> ```
> r->headers_in.safari_osx = 1;
> 
> ```
> 
> - 
> 
> ```
> }
> 
> ```

I would rather do

— a/src/http/ngx\_http\_request.c  
+++ b/src/http/ngx\_http\_request.c  
@@ -1493,7 +1493,9 @@ ngx\_http\_process\_user\_agent(ngx\_http\_req  
} else if (ngx\_strstrn(user\_agent, “Chrome/”, 7 - 1)) {  
r-\>headers\_in.chrome = 1;

- 

```
   } else if (ngx_strstrn(user_agent, "Safari/", 7 - 1)) {

```

- 

```
   } else if (ngx_strstrn(user_agent, "Safari/", 7 - 1)

```

- 

```
              && ngx_strstrn(user_agent, "Mac OS X", 8 - 1))

```

- 

```
   {
       r->headers_in.safari = 1;

   } else if (ngx_strstrn(user_agent, "Konqueror", 9 - 1)) {

```

As the sole purpose of r-\>headers\_in.safari bit is to activate  
this particular workaround. Any objections?

Maxim D.

---

<div class="post-metadata">

**Author:** ![ascarp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/eb8c5e/32.png) [@ascarp](https://www.ruby-forum.com/u/ascarp)\
**Post date:** [March 4, 2012, 10:09pm UTC](https://www.ruby-forum.com/t/latency-problem-with-one-browser/217475/14 "2012-03-04T22:09:33Z")

</div>

Hi Maxim,

> Restricting the workaround to something like “Safari on Mac OS X”  
> would be fine too, though it’s mostly orthogonal to changing the  
> default.

I believe this patch is sufficient.

“Mac OS X” string is present in all affected devices, i.e.:

- Mozilla/5.0 (Macintosh; Intel Mac OS X 10\_8) …
- Mozilla/5.0 (iPad; CPU OS 5\_0\_1 like Mac OS X) …
- Mozilla/5.0 (iPhone; CPU iPhone OS 5\_0\_1 like Mac OS X) …
- Mozilla/5.0 (iPod; CPU iPhone OS 5\_0\_1 like Mac OS X) …

— src/http/ngx\_http\_request.c.orig Sun Mar 4 20:53:14 2012  
+++ src/http/ngx\_http\_request.c Sun Mar 4 20:55:36 2012  
@@ -1496,6 +1496,10 @@ ngx\_http\_process\_user\_agent(ngx\_http\_request\_t  
\*r, ngx  
} else if (ngx\_strstrn(user\_agent, “Safari/”, 7 - 1)) {  
r-\>headers\_in.safari = 1;

- 

```
       if (ngx_strstrn(user_agent, "Mac OS X", 8 - 1)) {

```

- 

```
           r->headers_in.safari_osx = 1;

```

- 

```
       }

```

- 

```
   } else if (ngx_strstrn(user_agent, "Konqueror", 9 - 1)) {
       r->headers_in.konqueror = 1;
   }

```

— src/http/ngx\_http\_request.h.orig Sun Mar 4 20:55:38 2012  
+++ src/http/ngx\_http\_request.h Sun Mar 4 20:56:04 2012  
@@ -228,6 +228,7 @@ typedef struct {  
unsigned gecko:1;  
unsigned chrome:1;  
unsigned safari:1;

- unsigned safari\_osx:1;  
unsigned konqueror:1;  
} ngx\_http\_headers\_in\_t;

— src/http/ngx\_http\_core\_module.c.orig Sun Mar 4 20:56:25 2012  
+++ src/http/ngx\_http\_core\_module.c Sun Mar 4 20:56:42 2012  
@@ -1485,7 +1485,7 @@ ngx\_http\_update\_location\_config(ngx\_http\_request\_t  
\*r)  
\*/  
r-\>keepalive = 0;

- 

```
   } else if (r->headers_in.safari

```

- 

```
   } else if (r->headers_in.safari_osx
              && (clcf->keepalive_disable
                  & NGX_HTTP_KEEPALIVE_DISABLE_SAFARI))
   {

```

Best regards,  
Piotr S. \< [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) \>
