Hi,

You made an error. With Output frontend, you have to use the start()
method, not the load() one

If you comment your header() call, you will see error messages.

Following code works perfectly for me :

<?php

require_once 'Zend/Cache.php';
require_once 'Zend/Http/Client.php';

$frontend = 'Output';
$frontendOpts = array(
   'caching' => true,
   'lifetime' => 3600
);

$backend  = 'File';
$backendOpts = array(
   'cache_dir' => '/tmp/'
);

$cache = Zend_Cache::factory($frontend, $backend, $frontendOpts, $backendOpts);

header('Content-Type: image/gif');

$url='http://static.php.net/www.php.net/images/php.gif';
$cacheID='picture';

if (!($cache->start($cacheID))) {

   $http = new Zend_Http_Client($url);
   $http->setHeaders('User-Agent', $_SERVER['HTTP_USER_AGENT']);
   $http->setHeaders('Referer',    'http://' .
$http->getUri()->getHost() . '/');
   $res = $http->request('GET');
   $img = $res->getRawBody();

   imagegif(imagecreatefromstring($img));

   $cache->end();
}

?>

Regards

2008/9/20 Kai Meder <[EMAIL PROTECTED]>:
> Hello,
>
> I am trying to create an Image-proxy which caches image-urls on disk and
> outputs these jpegs to the browser.
> The following code wont work. On the first Cache Miss, the image is properly
> shown. On each following Cache Hit, the image is not displayed (invalid
> data). The cache file on disk contains the proper jpeg-image, at least
> irfanview recognizes it being jpeg...
> Any hint? Thanks!
> Kai
>
> $frontend = 'Output';
> $frontendOpts = array(
>        'caching' => true,
>        'cache_id_prefix' => 'ImageServiceProxy_',
>        'lifetime' => NULL,
>        'ignore_user_abort' => true
> );
>
> $backend  = 'File';
> $backendOpts = array(
>        'cache_dir' => CACHEDIR,
>        'read_control' => false,
>        'hashed_directory_level' => 3,
> );
>
> $cache = Zend_Cache::factory($frontend, $backend, $frontendOpts,
> $backendOpts);
>
> header('Content-Type: image/jpeg');
>
> if (!$cache->load($cacheID)) {
>
>        $http = new Zend_Http_Client($url);
>        $http->setHeaders('User-Agent', $_SERVER['HTTP_USER_AGENT']);
>        $http->setHeaders('Referer',    'http://' .
> $http->getUri()->getHost() . '/');
>        $res = $http->request('GET');
>        $img = $res->getRawBody();
>
>        imagejpeg(imagecreatefromstring($img));
>
>        $cache->end();
> }
> exit;
>



-- 
Fabien MARTY
[EMAIL PROTECTED]

Reply via email to