Easy caching for PHP

0

Posted by nick | Posted in PHP | Posted on May 17 2009

Tags: ,

I just implemented this cache class
http://www.phpguru.org/static/Caching on one of my sites.

The product detail page
ALR Hyperdrive 3.0 has eight or ten queries that run every time to pull the product info, nutrition info, reviews, manufacturer info, category info, etc…  This cache class provides the ability to store either output cache (html) or data cache (query results) in a file.  Each time the page is loaded, we’ll first check if there is a cached file of the output before running all the queries.  If there is a cache file, we’ll grab it and display.  If not, we’ll run the queries as usual and then save the output to a file.  We’re able to set an expiration on the cache file so it automatically refreshes itself in case the content has changed.

Example for caching output

    if (!OutputCache::Start("myGroup", "myID", 600)) {
 
        // Generate some output (as you do)...
 
        OutputCache::End();
    }

Example for caching data structures and query results

    if (!$data = DataCache::Get("myGroup", "myOtherID")) {
 
        $result = $db->query("SELECT BIG_ASS_QUERY()");
 
        DataCache::Put("myGroup", "myOtherID", 600, $result);
    }
 
    // Do something useful with $result

The page on my site ALR Hyperdrive 3.0 took on average 9 seconds from the time I clicked the refresh button until it was completely loaded.  I added the few lines of code for output caching on the page so it would skip all product related queries and it then averaged 7.5 seconds per page load and database processing and bandwidth in the meantime.  I was hoping the pages would load in two or three seconds, but this is a great improvement for the little effort it took.

  • Share/Bookmark

Safari text too bold solution

2

Posted by nick | Posted in Development | Posted on May 09 2009

Tags: ,

I downloaded Safari 3.2.2 for windows a little while ago and immediately found my designs screwed up and out of whack because all the text was much bolder than it should have been. It’s something to do with Safari. The fix is to add the below line in your stylesheet. You can add it to the body tag for a site wide fix if you want.

text-shadow: #000000 0 0 0px;

  • Share/Bookmark

cron “No input file specified” solved

1

Posted by nick | Posted in Development | Posted on May 06 2009

Tags:

For quite a while unknown to me my script was not automatically running via the cron job I setup.  After entering my email address in cpanel’s standard cron interface, the email I received said:

Status: 404 Not Found
X-Powered-By: PHP/5.2.5
Content-type: text/html

No input file specified.

A few minutes of searching the net uncovered my mistake. I had a url variable on the command, which cause it not to work. Instead of
php /home/mysite/public_html/filename.php?method=automated
use
php /home/mysite/public_html/filename.php method=automated .

Exclude the question mark in the url variable and that made it work.

  • Share/Bookmark