What's your tips to speed up PHP server?
We have running a php server at #uviba. But our server is a bit slower. I don't know how to speed it up.
First identify the source of the slowness. Unless you're having a huge traffic, I doubt it is related to PHP server itself. Maybe you have slow SQL queries? Do you have a caching system in place?
SQL queries are optimized. Yes, we use a caching system for a few things.
- Use newest PHP version. PHP 7.3 is faster then 7.2, 7.1, 7.0
- If you guys write the stuff yourselves:
- use
\function
instead offunction
(php internal function like\sort()
\usort
\array_*
- use
'
instead of"
- don't use relative paths
- use
- Do you use composer? Use the optimizing stuff (https://getcomposer.org/doc/articles/autoloader-optimization.md)
- Give PHP more RAM
But the problem is rarely PHP, mostly it is file operations or database queries. Very rarely PHP is the direct cause.
@spekulatius π
the list could of course be longer. these are rather small fixes. it should be clear to everyone, if the code should be performant, you have to consider this from the very beginning.
logic alone makes a difference: using of sentinals, performant loop writing, unnecessary execution of code.
but as said before, often it is more database queries or the database server itself that is the bottelneck.
1) Are you using a PHP framework eg Symfony or Laravel? There is doc to optimize your website if that's the case.
2) Optimized SQL queries are not enough if your database tables are not optimized. If your business operations are read-intensive, consider denormalizing your database or switching to NoSQL.
3) Are you using a CDN to speed up HTML delivery (ie Cloudflare)?
- implement nginx proxy cache. https://serversforhackers.com/c/nginx-caching
- Implement varnish https://varnish-cache.org/
- Implement redis cache or memcached. (look graphs from sergio twitter).
Please sign in to leave a comment.