Remove Googlebot and Bingbot session files from Magento

Clear session storage from Googlebot and Bingbot sessions with these Linux commands.

If you save your sessions in the file system, your Magento sessions folder gets overfilled with session files and slows down your site. Because they do not keep sessions, when Googlebot or Bingbot scan your site they create extra sessions that shouldn’t be there.

To solve this problem I recommend removing your session files with “Googlebot” and “Bingbot” inside of them.

First test this code on your server:

1
grep -il 'googlebot' /MAGENTO_PATH/public_html/var/session/*

This will output all the session files containing “Googlebot” in your /session folder. You should have at least some. If not, then double-check your path.

After your path is correct, you can setup your CRON to run daily to remove those unnecessary session files:

1
2
grep -ilq 'googlebot' /MAGENTO_PATH/public_html/var/session/* | xargs rm -f
grep -ilq 'bingbot' /MAGENTO_PATH/public_html/var/session/* | xargs rm -f

Leave a Reply