Tag Archives: performance

Improve performance: Save the Request and Use Signed Cookies

These are 2 ideas that I have just heard on a presentation. To gain performance with your application, save the requests (dont worry much with pageload) and use a signed cookie to autenticate uses instead of checking the sessions.

The save the requests concept is pretty simple: If you browser already cached something, unless you really need to reload that file, save that request and let it cached. For example, don’t change an image name or add an identifier to a css file unless strictly needed. That will save a request, therefore gaining performance.

The signed cookie is an interesting concept. If you take a look, the read time to the database (or cache mechanism) to check if the use is authenticated is greater than your application checking for a signed cookie. Read the cookie and if is there, authenticate the user.

I really did like these 2 ideas and probably will start using them on my apps. Anyway, sharing the tip.


MySQL Tricks

This is a small trick with MySQL that will make your paginate methods and queries faster.

When doing a SELECT use SQL_CALC_FOUND_ROWS on it so after the select is done you will already have the count of the rows even if you are doing a limit.

Example:

SELECT SQL_CALC_FOUND_ROWS id, name, created FROM my_table LIMIT 0,10;

This will return the 10 first results from the table, but if you do

SELECT FOUND_ROWS();

It will return the number of rows that it would have been if the prior select was done without the limit.

This small trick can speed up considerably the pagination with PHP and the speed of your queries since you now don’t have to do a SELECT count(id) FROM my_table to know how many records you have.


Using LEFT JOINS and Hellfire the MySQL performance guide

I occasionally play WOW (World of Warcraft) and as a “Lock” I know that I shouldn’t use hellfire in any instance (bg or not), is a waste of energy and give’s no result.

With MySQL LEFT JOINS is no different. Off course there will be cases where you will be required to use a LEFT JOIN (and in most of these, normalizing the tables would work), but if you can avoid it, the performance gain on the queries is considerable. There are options for not using left joins, but here are a couple:

1. INNER JOINS (should be your first and mostly only option)

2. INNER JOINS …

I’m no MySQL master, but I have received a good article today that give’s a bunch of MySQL optimization tips. Check it out:

http://www.informit.com/articles/article.aspx?p=377652

This article is dedicated to all my friends and co-workers that play with me on WOW and annoy the hell out me when I use a LEFT JOIN :)


Building High Performance and High Traffic PHP Applications with MySQL – Part 2: Best Practices – Slides

Building High Performance and High Traffic PHP Applications with MySQL  – Part 2: Best Practices

Download here: http://event.on24.com/event/33/24/48/rt/1/documents/slidepdf/081611_webinar2final.pdf


Dont Panic

Good post from PHP Advent :

http://phpadvent.org/2010/dont-panic-by-derick-rethans


Follow

Get every new post delivered to your Inbox.

Join 236 other followers

%d bloggers like this: