# Serving direct static image vs via php

**URL:** <https://www.ruby-forum.com/t/serving-direct-static-image-vs-via-php/218148>\
**Category:** NGINX\
**Created:** [March 22, 2012, 3:13pm UTC](https://www.ruby-forum.com/t/serving-direct-static-image-vs-via-php/218148 "2012-03-22T15:13:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 22, 2012, 3:13pm UTC](https://www.ruby-forum.com/t/serving-direct-static-image-vs-via-php/218148/1 "2012-03-22T15:13:54Z")

</div>

Serving static files is the native behavior of nginx, and when we use  
gateway for scripting, it needs more works by nginx. Thus, loading a php  
file should take more time than loading an image file.

I compare the speed of loading an image file with serving via php by

$image=imagecreatefromjpeg($imagepath);  
header(‘Content-Type: image/jpeg’);  
imagejpeg($image);

Surprisingly (at least to me), the speed of loading the image via php  
was 50 - 70% faster than loading the original image file directly. What  
is the reason for this peculiar behavior?

I tested with Pingdom. The difference was in Receive step, which is  
associated with downloading the data.

Posted at Nginx Forum:

> **[Serving direct static image vs via php](https://forum.nginx.org/read.php?2,224228,224228#msg-224228)**
>
> Serving static files is the native behavior of nginx, and when we use gateway for scripting, it needs more works by nginx. Thus, loading a php file should take more time than loading an image file. I compare the speed of loading an image file with...
