I have to do this periodically when the error presents itself. For my server I have to do these things:
SSH in as root. > CD to the /var/www/vhosts/ or where ever the site is stored > SU to the client's web user > and then I have to denote where the php version is located. In my instance it's /opt/plesk/php/7.0/bin/php then add -d and I have to increase the memory before typing bin/magento and setup:di:compile, so from command line # [location of php on my server]php/[ver]/bin/php -d memory_limit=8G bin/magento setup:di:compile
Then I exit that user after all the files are loaded as the web user, so I don't have to back and chown all the files that came in as root (if hadn't SU). Next run:
php bin/magento indexer:status
php bin/magento cache:flush
php bin/magento cache:clean
php bin\magento indexer:reindex
If they don't run or error out, you may have to increase your memory like above, for each command.