julio julio - 3 months ago 7x
PHP Question

check if object exists in Cloud Files (PHP API)

I've just started working with the PHP API for Rackspace Cloud Files. So far so good-- but I am using it as sort of a poor man's memcache, storing key/value pairs of serialized data.

My app attempts to grab the existing cached object by its key ('name' in the API language) using something like this:

$obj = $this->container->get_object($key);

The problem is, if the object doesn't exist, the API throws a fatal error rather than simply returning
. The "right" way to do this by the API would probably be to do a

$objs = $this->container->list_objects();

and then check for my
value in that list. However, this seems way more time/CPU intensive than just returning
from the

Is there a way to do a "search for object" or "check if object exists" in Cloud Files?



I sent them a pull request and hope it'll get included.


My pull-request includes an example, for you it would be similar to this:

$object = new CF_Object($this->container, 'key');
if ($object->exists() === false) {
    echo "The object '{$object->name}' does not exist.";