I haven't properly confirmed though a lot of people are saying PHP doesn't run garbage collection (e.g. clearing out expired session files) on localhost. Also if this has changed I don't know the old/new version cut-off either.
If this is true then you need to first determine if the client (who you should always verify, never trust) has sent the HTTP_HOST request header. If so, there are the three basic values that you'll see unlike on a live server (you'll instead see something like 'www.example.com' or 'example.com'). Don't forget about modifications you've made on your OS's hosts file (or equivalent). Don't forget any relevant networking/router/modem settings too, again, if applicable.
You could append this to your custom local homepage, setup a maintenance page or if you're running a template system append this after the XML/HTML has been sent though you very likely don't want extra stuff running on your live server only intended for your local server unless you do it after flushing the page and continue processing afterwards:
<?php
if (isset($_SERVER['HTTP_HOST']) && in_array($_SERVER['HTTP_HOST'], array('127.0.0.1','::1','localhost'))
{
gc_collect_cycles();
}
?>