Finally after 3 years fixed the intermittent yet persistent 500 errors on our website.
Also discovered major irritating bug in almost all browsers which was screwing up our PHP script for delivering newsletter bribe hex codes (see here for a description). I don't actually think that this exact bug was occurring as such - our work Squid proxy here was doing it. When Squid was bypassed the site worked as expected.
That took 2 hours to find and fix. Chaz's PHP code doesn't help, and just imagine what fun it is debugging terrible PHP code when PHP itself is a macrocosm of brainf**k itself. I hate the web and all of its shit, half-baked, hand-wavy, loosely-coupled, "oh-we'll-deal-with-errors-some-other-time" bullshit.