get_headers() function results in memory leak

In the sites I support I`ve seen many problems with the case-sensitivity of permalinks. As you might now part of the wordpress permalink sanitization process is converting the permalink to lowercase. In order to deal with the endless errors in webmaster tools I needed to find a way to reroute the requests for the uppercase addresses to their existing lowercase alternatives. The solution I came up was kind of slappy, but I thought it should do the trick. When a request is routed to my theme`s 404 page I check if there is an existing page, by getting its headers with get_headers() and if the page/post in fact exists i use 301 to redirect the user there. Sounds plausible…but guess what it killed the server(which is the main reason I desided to share it in our wordpress tutorials)!

Turned out that get_headers() function not only loads the headers of the page, but the whole page. And if the page is  in fact missing it goes to 404 again which again calls get_headers() causing infinite loop.  This started eating the entire VPS memory, until it kills all sites on it with Internal Server Error 500.

As a useful(not server killing) alternative for wordpress I`ve found wp_get_http_headers() (You can read more about it in the wordpress codex here ). Very helpful alternative for get_headers() for wordpress users.