Tutorial :Help with a possible performance problem (in a php pagination)



Question:

Hello I have a search engine, but in the pagination I have to redefine the searchterm in the url, I mean <a href='http://mysite.com/search.php?q=searchTerm&currentPage=2'>Next</a>.

Please tell me if I'm doing it well or there is another way to do it


Solution:1

I can't see the code on PHP's side so you may already know this, but one thing I could suggest in this case:

Make sure you use a LIMIT clause in your query to select only the rows you want to show, and explicitly select the columns you want to use.

Most likely, the expensive part of the whole operation is going to be the searchterm component, not the pagination component. Unless you have a high volume of identical search terms, caching will probably not help.


Solution:2

Unless you're anticipating extremely high traffic, this isn't likely to be a problem. This is the standard way pagination is done - if you find you do have performance problems, reconsider the way you're doing things then. There's no reason to prematurely optimize. Don't invite someone to come here and quote Knuth, please!

One alternative is to send more than one page of data to the client at once, and then paginate with Ajax. The drawback is that the first request will take a little longer to create and send, use more bandwidth, and chances are many users will never go beyond page one on a given query.

If you're looking to increase efficiency or performance in general, it's a fairly large topic. You can add indexing, caching, explore alternative data stores, add servers, and so on. You could say, run the query to get 5 pages at once, store the results in memcache, and access those until you need a new 5 pages.

It depends what actually ends up being a bottleneck. Often, it's something different than you expected, and often what works as a solution is unexpected as well.


Solution:3

Using $_GET has for all intents & purposes no effect on performance vs any other way to do this. Also, since these urls aren't doing anything but retrieving information, it's fine (or actually, appropriate) to use this query string vs post.

In other words: you're doing it right as far as I see it. For creating/editing/deleting data, use a with method="post", for reading data usually use a link (or a with method="get").


Solution:4

Good thing you worry about performance in the first place, but I totally agree with Alex JL: it all depends.
If you're still interested in pagination and performance I created something of a tutorial how to use javascript along with php. Code can of course be much nicer and you should adapt to your search query. Anyway, maybe it helps.
See http://www.kwalinux.nl/pagination/849/


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »