I have a php 5.4
/mysql
website with 5 million hits per day, running on a linux server with nginx
and php-fpm
. Database is located on a separate server.
I've noticed, that at peak times, my webserver load gets up to 15, instead of normal 4 for quad core processor. I've profiled my php application with xdebug
and xhprof, and saw, that 90% of CPU work is done by htmlspecialchars()
function in Twig
templates that I use to display data. There are sometimes from 100 to 1000 htmlspecialchars()
calls per page. I've tried to reduce unnacessary escaping, but still it cannot be avoided.
Is there any way I can reduce CPU usage by htmlspecialchars()
function? Maybe there is some kind of caching in php for this? Or there is there another way?