You won't want to code this in PHP. Rather, you might consider making API calls to an external tool / service that you run:
I've been experimenting with this and have setup an image server with iskdamon [1]. What you are asking for is called Content Based Image Retrieval (CBIR) [2].
It works like this:
I can query the image server via several methods:
Check out the docs with isk-daemon. They are pretty good, and I'm surprised how good it works.
[1] - http://www.imgseek.net/isk-daemon [2] - http://en.wikipedia.org/wiki/Content-based_image_retrieval
Symlink Windows libraries like feature in addition to tags.. ability to view non tagged. images/media .
View/browse 2-3 simultaneous images in view panel(good for large monitors)
Quick notes feature for folder or media file independent of file metadata. useful for documenting source, etc.
Finding image duplicates using hash may not be enough.. Imgseek or something similar to what Digikam is using.
Load images in slideshow or gallery thumbnail view recursively for quick browsing.