I have a php 5.4 / mysql website with 5 million views per day, running on a linux server with nginx and php-fpm . The database is located on a separate server.
I noticed that in peak times my web server load reaches 15, instead of the usual 4 for a quad-core processor. I profiled my php application with xdebug and xhprof and saw that 90% of the CPU work is done by htmlspecialchars() in the Twig templates that I use to display the data. Sometimes from 100 to 1000 htmlspecialchars() calls per page. I tried to reduce unnecessary shielding, but this cannot be avoided.
Is there a way to reduce CPU usage by htmlspecialchars() ? Maybe there is some kind of caching in php for this? Or is there another way?
source share