# Remove get_browser() from core

- Thread: https://externals.io/message/89519
- Original archive: https://news-web.php.net/php.internals/89519
- Started by Martin Keckeis on 2015-12-02T07:52:01+00:00
- Messages: 7
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #89519 — Martin Keckeis — 2015-12-02T07:52:01+00:00

URL: https://externals.io/message/89519#89519

Hello together,

i think it's time to deprecate the function `get_browser()`.

The reason is simple: Since the browscap.ini file has grown a lot this
function does need way too much time, see here for example
http://stackoverflow.com/questions/12067641/get-browser-slowing-down-page-load-any-alternative

The underlying browscap.ini file is still a very resource to use and there
are very good official packages out there to use it
https://packagist.org/packages/browscap/browscap-php

I also compared the browscap.ini file to other UserAgent parsers around and
it looks still good
http://thadafinser.github.io/UserAgentParserComparison/results/index.html

Alternative is only an optimization for this function, but i think it's not
worth, since the offical package is good.

What you guys think?


Best regards
Martin

---

## #89523 — Andrea Faulds — 2015-12-02T20:02:48+00:00

URL: https://externals.io/message/89519#89523 · In reply to: #89519

Hi Martin,

Martin Keckeis wrote:
> i think it's time to deprecate the function `get_browser()`.
>
> The reason is simple: Since the browscap.ini file has grown a lot this
> function does need way too much time, see here for example
> http://stackoverflow.com/questions/12067641/get-browser-slowing-down-page-load-any-alternative
>
> The underlying browscap.ini file is still a very resource to use and there
> are very good official packages out there to use it
> https://packagist.org/packages/browscap/browscap-php
>
> I also compared the browscap.ini file to other UserAgent parsers around and
> it looks still good
> http://thadafinser.github.io/UserAgentParserComparison/results/index.html

I'd also support removing `get_browser()`, but for a different reason: it 
encourages user agent sniffing, which is a bad practice that has led to 
the mess that is modern User-Agent headers. The web is an open platform 
which degrades gracefully, where you can detect if browsers support 
features you need and adapt accordingly. Detecting specific browsers is 
harmful to competition and not future-proof.

Thanks.

-- 
Andrea Faulds
http://ajf.me/

---

## #89561 — Martin Keckeis — 2015-12-03T12:44:22+00:00

URL: https://externals.io/message/89519#89561 · In reply to: #89523

2015-12-02 21:02 GMT+01:00 Andrea Faulds <ajf@ajf.me>:

> Hi Martin,
>
> Martin Keckeis wrote:
>
> > […]
>
> I'd also support removing `get_browser()`, but for a different reason: it
> encourages user agent sniffing, which is a bad practice that has led to the
> mess that is modern User-Agent headers. The web is an open platform which
> degrades gracefully, where you can detect if browsers support features you
> need and adapt accordingly. Detecting specific browsers is harmful to
> competition and not future-proof.
>
> Thanks.
>
> --
> Andrea Faulds
> http://ajf.me/
>
> --
> 
> 
>
>
User agent sniffing was sadly missused to detect e.g. if it's a mobile
device and redirect to a mobile page -> which is wrong right.

But user agent sniffing is still a good information source for different
things:
- statistics / analytics
- cross selling
- ...

But that's not needed in a language core anyway :-)

---

## #89565 — Zeev Suraski — 2015-12-03T13:31:07+00:00

URL: https://externals.io/message/89519#89565 · In reply to: #89519

> 
> 
> Hello together,
> 
> i think it's time to deprecate the function `get_browser()`.
> 

+1.  Would be nice if we could point to a recommended alternative in the deprecation message.

Zeev

---

## #89566 — Pierre Joye — 2015-12-03T13:38:53+00:00

URL: https://externals.io/message/89519#89566 · In reply to: #89565

>
>
> > […]
wrote:
> > […]
>
> +1.  Would be nice if we could point to a recommended alternative in the
deprecation message.

+1 too.
Hard to do it in the error message but there are plenty of tools doing a
far better jobs using log analysis (for the stats).

Cheers,
Pierre

---

## #89567 — bjorn.x.larsson@telia.com — 2015-12-03T13:59:52+00:00

URL: https://externals.io/message/89519#89567 · In reply to: #89561

Den 2015-12-03 kl. 13:44, skrev Martin Keckeis:
> 2015-12-02 21:02 GMT+01:00 Andrea Faulds <ajf@ajf.me>:
>
> > […]
> User agent sniffing was sadly missused to detect e.g. if it's a mobile
> device and redirect to a mobile page -> which is wrong right.
>
> But user agent sniffing is still a good information source for different
> things:
> - statistics / analytics
> - cross selling
> - ...
>
> But that's not needed in a language core anyway :-)
>
Also good for cuctomer support. Knowing roughly which browser
users have is quite helpful for e.g. finding errors in web apps.

//Björn

---

## #89581 — Martin Keckeis — 2015-12-03T16:21:36+00:00

URL: https://externals.io/message/89519#89581 · In reply to: #89566

2015-12-03 14:38 GMT+01:00 Pierre Joye <pierre.php@gmail.com>:

>
> 
> > […]
> wrote:
> > […]
> deprecation message.
>
> +1 too.
> Hard to do it in the error message but there are plenty of tools doing a
> far better jobs using log analysis (for the stats).
>
> Cheers,
> Pierre
>
A message would really be good.

But `get_browser()` is a bit special, since it returns the "browser
capabilities" which only this type of parser can do.
So the "dropin" replacement would be
https://github.com/browscap/browscap-php

I will soon publish a new check with >1000k user agents analyzed by 9
different parsers out there...will notice you if it's done.

Best regards
Martin
