Archive for November, 2007

Zenphoto plugin: Static Cache Control

Stealing a page from WP Super Cache’s book, I’ve written a plugin for Zenphoto that caches (and optionally gzips) Zenphoto pages on the file system to minimize PHP execution, making your dynamic image gallery run almost as fast and light on resources as a static website. Read more about Zenphoto staticCacheControl here.

Nagging question:
Using PHP, is it impossible to redirect a browser to a different URL without changing the browser’s URL visibly? In other words, can transparent URL rewriting Apache-style be accomplished with PHP?

If you liked this post, please subscribe to my feed. Thanks for visiting!

Zenphoto plugin: Link Prefetching Hints

printPrefetchHints is a plugin that improves Zenphoto image browsing performance by printing link prefetching hints which instruct Mozilla-based browsers to preload the next page and image in the album.

Link prefetching hints are only supported by Mozilla-based browsers. The hints are completely harmless as they are ignored by other browsers like Internet Explorer. You can test your browser to see if it supports prefetching.

PHP: Measuring code execution time

The following code measures the amount of time it takes to execute a chunk of code.

In PHP 4 (source):

$time1 = explode(' ', microtime());
/* your chunk of code here */
$time2 = explode(' ', microtime());
$begintime = $time1[1] + $time1[0];
$endtime = $time2[1] + $time2[0];
$totaltime = $endtime - $begintime;
echo "\n<!-- Executed in $totaltime sec -->\n";

In PHP 5 (source):

$time_start = microtime(true);
/* your chunk of code here */
$time_end = microtime(true);
$time = $time_end - $time_start;
echo "\n<!-- Executed in $time sec -->\n";

Bionic Woman S01E08 720p HDTV X264 DIMENSION

Bionic Woman S01E08 720p HDTV X264

House S04E09 720p HDTV X264 DIMENSION

House S04E09 720p HDTV X264

Zenphoto plugin: HTTP Cache Control

I’ve released a plugin for Zenphoto, httpCacheControl, which makes your Zenphoto pages cacheable in order to increase site performance and minimize resource usage. It uses the doConditionalGet() function I released yesterday.

Again, feedback, suggestions, improvements, criticisms very much welcome!

PHP: speed of string comparison functions

Here is a recent benchmark of various PHP string comparison functions. Not surprisingly, the fastest is strpos. But did you know that preg_match is faster than strstr and not much slower than strpos? This contradicts the following note in the official PHP manual:

Do not use preg_match() if you only want to check if one string is contained in another string. Use strpos() or strstr() instead as they will be faster.

ereg is by far the slowest.

So, the best function to use to do a simple check to see if a string contains a particular substring is strpos. In all other cases preg_match might be superior to strstr. YMMV.