![]() |
Optimizing PHP Code
I've created stuff in php before where it looks fine to begin with and then later down the road when the site starts getting traffic... the code becomes a problem where load balancing had to come into play. I've been using xdebug to find long running functions ...Can anyone give some pointers on fully optimizing your php code?
|
You could try compressing the html using ob_start("gz_handler");
http://phplens.com/lens/php-book/opt...ugging-php.php Another google article I found: http://devilib.com/solutions-framewo...n-tips-faster/ |
Reduce the number of SQL queries you execute on each page load. Every SQL query is a call to the SQL server which takes some time.
|
Quote:
|
Quote:
EXPLAIN command before SELECT and then analyse the results. You'll want to stay well away from ALL queries as this means that MySQL has had to scan the entire table (or more) to find what it's looking for. See this page in MySQL's documentation for further information. |
One of the first steps is to optimize your database. Check the schema, add index's when needed, check your queries, etc. Also choosing the correct table type can help a lot. Watch out for locked tables / rows. Or COUNT(*) on IonnoDB tables... They can kill apps.
Another one is to make sure you're caching data you need to cache. Example would be, besides HTML pages, if you generate thumbnails or other graphics with PHP, to cache and save those (honestly, when does a thumbnail change all by itself?) Also, look at how your system/core php files are designed. Are you using multiple require / include statements that aren't needed? Are your include files excessively large? Could they be split into smaller more specific tools / packages ? I mention this because everytime you need to require a file, it server must then read disk. Which doesnt seem so bad... but increase traffic and average hit per page... I've seen some sites/pages have up to 15 - 25 includes get bombed. Just little tid bits to look out for... Edit: Oh, and also, the point about the file size of PHP scripts... PHP is an interpreted language, which means if you can get it done in less code, get it done. So having excessive unneeded code for PHP to compile and process slows down the page. |
What if the server you host your website on was dedicated, for example I have a dedicated 1and1 server, runs my one website, PHP Data driven.
(Win2k3, IIS, before you laugh theres more reason behind choosing that toolset). What sort of things can I do on the Server side of things to make PHP and MySQL database queries run faster? |
Quote:
|
How would LAMP (or more specifically WAMP) help him?
|
Aye but like I said, I have reason for going Microsoft. I will enventually be setting up Virtual Linux server so I can have a LAMP service - but does that actually Optimize your PHP? Or just work really well with it?
|
Lol LAMP was a bit of a joke, but PHP does run more stable and quicker on LAMP generally speaking, but thats another point.
Try some code optimisers: http://eaccelerator.net/ http://www.zend.com/products/zend_optimizer |
I am using lamp... running on SuSE w/ Apache2, MySQL, PHP5 on a box with 4xCPUs and 2GB of RAM... I'm talking about optimizing code. Problem looks like it might be with this MIME email class that I'm using... there is a function that takes a LONG time to execute. I use apache benchmark to stress test the box while running a profiler (xdebug) to see where the source of the problem might be...
|
Quote:
You also want to look at the number or writes you have to do the database, and consider if your I/O volume does require you to replicate, or cluster. Obviously at some point you reach the limits of your DB hardware limitations. And when that happens, bad things happen. I'd also look into the schema of data, if you find that you're running a lot of complicated searches or something of the like, you should cache the search queries. I worked before on a site, where when one person searched for a term, that was cached, everyday the cache starts over. So if 'Bob' searches for 'panda images', he finds what he wants, and the server caches those results. Then, if 'Jill' searches for 'panda images' as well, she gets the same results, just without any extra load on the server. There's an infinite number of possibilities of ways to cache data. I'd recommend checking into a way that is most adaptable to your site or projections needs. |
| All times are GMT. The time now is 05:28 AM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0