You'll see a significant performance improvement if you don't load the files contents into PHP. The best way to do this is with an apache mod called X-SendFile. (http://tn123.ath.cx/mod_xsendfile/) but if you cant install the module, then you'll want to use fpassthru(). Fopen/fread and file_get_contents approaches have significant overhead and really shouldn't be used.

Chris Martin wrote:
The following self-contained example works fine for me in my environment. Try
it on yours, it may help to narrow the problem down further:

public function imgtestAction()
{
    $this->_helper->layout->disableLayout();

    $logo =
file_get_contents("http://framework.zend.com/images/PoweredBy_ZF_4LightBG.png";);
    $type = 'image/png';

    $response = $this->getFrontController()->getResponse();

    $response->setHeader('Content-Type', $type, true);
    $response->setHeader('Content-Length', count($logo), true);
    $response->setHeader('Content-Transfer-Encoding', 'binary', true);
    $response->setHeader('Cache-Control', 'max-age=3600, must-revalidate',
true);
    $response->setBody($logo);

    $response->sendResponse();
    exit;
}



Michael Crumm wrote:
Giuliano,

Thanks for the thought!  Unfortunately, I tried that as well and still
can't
seem to get an image out.
Here's my controller action:

    public function viewAction()
    {
        $this->_helper->layout->disableLayout();
        $logo = $this->_logo;
        $modifiedDateGM = gmdate('D, d M Y H:i:s',
strtotime($logo['modified'])) . ' GMT';

        $response = $this->getFrontController()->getResponse();
        $response->setHeader('Last-Modified', $modifiedDateGM, true);
        $response->setHeader('Content-Type', $logo['type'], true);
        $response->setHeader('Content-Length', $logo['size'], true);
        $response->setHeader('Content-Transfer-Encoding', 'binary', true);
        $response->setHeader('Cache-Control', 'max-age=3600,
must-revalidate', true);
        $response->setBody($logo['data']);
        $response->sendResponse();
        exit;
    }

Seems like someone over in the zf-db list was having a similar issue - I'm
having a similar discussion over there.

Any more thoughts?

-Mike




--

Kevin McArthur

StormTide Digital Studios Inc.
Author of the recently published book, "Pro PHP"
http://www.stormtide.ca

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Reply via email to