krazyjosh, what he was trying to say is that alot of projects include tens of files, which will affect your performance alot. I try to minimize the includes required.
Ofcourse, if you use some open source project, you have no control over this.
And what I meant by require versus require_once is that require_once does an extra check to see if the file has already been required. So require is faster. However, in php 5.2 they seem to have fixed this performance issue.
And again, as this is about performance issues, ctype_digit will be faster than any regex to see if a variable is indeed numerical. Always use ctype_whatever if that's just what you need. ctype_alnum etc.
- What's also great is that APC and memcache amongst others allow you to save stuff to memory, which means it's really fast. Do check that out.
- One other tip, if you have a page that requires that you update the view_count, don't do that immediately every time. It has to create a table lock and what not and it's slow. Save it to memory or INSERT in a memory table and then write that out as a query once per hour.
- Another tip, if you have multiple inserts use this sql statement:
insert into table (col, col2) values (1, 2), (3, 4); etc..
- Only fetch the columns you need. Don't do select * from table, do select id, name from table if these are the only values you need. Saves up memory and is generally faster.
- If you're using PHP 5, use mysqli_ instead of mysql_ functions.
- Use multi_curl if you want to fetch multiple pages (from different servers) at once.
- Use UPDATE LOW_PRIORITY if you want.
- Always use indexes on your tables.
- Use a PHP profiler to find out where your code is slow: xdebug, apd.
- Log slow queries with mysql slow query log.
- Golden tip: use mysqlnd; a native PHP driver for mysql. Much faster.
He used Xdebug and system statistics to test PHP 5 with mysqlnd. Some of his findings:
Connection time has gone down: from ~900ms down to ~320ms
Better query time: from ~350ms down to ~300ms
Less memory consumption: ~30% according to server statistics
All in all he describes the mysqlnd test run with:
You can download it for PHP5, will be built-in with PHP6.