Posted 21 June 2006 - 06:56 PM
1. I have several places where the same SQL query is being run. For instance, if a person is viewing a post on my site, the query runs with each page load. The query is not overly complex although it does use 3 tables through 2 joins. Since the content in the post is not likely to change very often, I thought maybe it would be a good idea to cache the query results to a file. Then, when any user loads the page, it looks to the cache file for the results. If the data ever changes, I would flush the cache. Is it worth doing caching in this case or would it be quicker to query the DB? I currently use caches for search results, but these queries are usually more complex, involve pagination, and I actually don't want the search results to update while they are viewing them. I'm just trying to figure out what the threshold is for when caching becomes quicker than querying. If so, how would one handle concurrent access to a 'global' cache file? It seems that concurrent access would only be a problem when the cache was being written initially. After that, it is just read-only.
2. I have been building my site trying to separate the presentation from the processing by putting the processing routines in 'api' files and including those api files in my .php files that are being shown to the user. However, one api file is starting get kind of large (~2000 lines). If I have another file include this api file, but the script really only needs 2-3 functions out of the api file, isn't that wasted resources, or will the other functions not be parsed unless they are used?
Thought of a couple more.
3. I have seen that is more efficient to break out of PHP mode for large blocks of static HTML rather than echoing the whole thing out. But if one would be breaking out of PHP to output just a few lines, would that be more efficient still, or would it be best to echo them?
4. Generally speaking, how much time is too much time for a page to be generate on the server? I know that the internet connection can be a bottleneck but I'm not really worried about that as there is nothing I can do about it.
Posted 21 June 2006 - 07:05 PM
In terms of the API's that you spoke of. I think you really need to evaluate them and ask yourself whether any of them can broken into different objects. Exactly how closely related are all of these functions? Chances are many of them could be in their own classes thereby reducing the include file size for any one file.
Finally I suggest you try the benchmark PEAR package so that you have a firm numbers on the speed of things. You can set markers throughout your page and know exactly how long it takes to get from A to B to C. This can help you shave off bloated code in a more targeted fashion.
Hope you find some of that helpful, Buyo.
Posted 21 June 2006 - 08:24 PM
I am currently using the PHP mysql functions for database access. From what I see on this forum, the mysql functions are probably the fastest for DB access. For caching search results, I wrote my own routines which I think work very well and are quite efficient.
You are right on the API's they could be broken up. I wasn't sure if I needed to, but it looks like I should. Currently, everything is procedural but I could switch to using objects. I've heard that objects are not as efficient as procedural code, but maybe it would be worth switching for usability.
I have downloaded the benchmark package from the PEAR website. I will see if I can figure out how to use it. I don't really understand what PEAR is at this point. What exactly does PEAR do? I have apache2triad installed on my test box and I know that has PEAR installed on it. Does my hosting company have to have PEAR installed in order for me to use PEAR packages on their server?
Posted 21 June 2006 - 08:51 PM
then you do something like...
$timer = new Timer();
something like that. Anyway there are some examples included in the download, try looking at them. Let me stress, YOU DO NOT NEED TO INSTALL ANYTHING. Just include the files needed. Hope that helps.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users