peej/tonic — Issue #68: How to respond to an image request
Author: rgeddes
Created: 2012-01-19 15:14:34+00:00
State: open

Ubuntu-NGINX-FPM-PHP5

After getting the examples to work, I created my own resource and an associated resource class with get method. It basically delivered the following :

$response->code = Response::OK;
$response->addHeader('Content-type', 'text/html');
$response->body = <<

Hello world.

EOF;

When I ran the xdebug debugger, and noticed that, after the initial request/response was complete, a second request for the favicon came through xdebug.

I added the favicon to the head:

but the favicon.ico would not load... instead, the request for /path/favicon.ico returned a 404 message... that 404 was not displayed in the browser (I'm guessing because the original request filled the html body, and response for this extra, add-on resource is ignored...)

Finally, I modified the head element to this:

and created a resource class with a get method that delivers:

$response->code = Response::OK;
$response->addHeader('Content-type', 'image/x-icon');
$response->body = file_get_contents('./images/favicon.ico');

and that added the favicon.

Since images, and any other associated files like javascript or css, are resources, each file or collection of files has to be handled by resource class... does that sound correct?

If yes, do you have more samples showing different techniques to deliver different resources... eg pulling from a db, image files, and in general how to play with the http protocol to fine tune the delivery.

That sounds like alot of work compared to a file reference in an html tag attribute. Hopefully, the return on investment will pay off when fine tuning is required.