For the record, I've been considering moving to file system stored
files since this issue come about (as you could probably work out from
my original post)

My code is pretty simple as there are no fancy calculations or
processing, when the image is uploaded its thumb nailed then and the
thumb data stored in the same record on the db. My view image view is
just this:

<?php

header("Content-type: " . $photo['Photo']['type']);
header("Content-length: " . $photo['Photo']['size']);
header("Content-Disposition: " . (isset($attach) && $attach ?
'attachment' : 'inline') . "; filename=\"" . $photo['Photo']
['name'] ."\"");
header("Content-Description: PHP Generated Data");
header("Expires: Mon, 26 Jul 2038 05:00:00 GMT");
header('Last-Modified: '.gmdate('D, d M Y
H:i:s',strtotime($photo['Photo']['modified'])) . ' GMT');


print $photo['Photo']['data'];

exit();
?>

I added the last 2 headers to try and reduce the amount of the times
the server gets hit for a particular page load which helps. I
replicated the issue while running 'watch mysql proccesslist' and you
can see whats going on in the DB:

+-------+------+-----------+------+---------+------+-------
+------------------+
| Id    | User | Host      | db   | Command | Time | State |
Info             |
+-------+------+-----------+------+---------+------+-------
+------------------+
| 23086 | root | localhost | gpts | Sleep   | 117  |
|                  |
| 23087 | root | localhost | gpts | Sleep   | 116  |
|                  |
| 23088 | root | localhost | gpts | Sleep   | 115  |
|                  |
| 23144 | root | localhost |      | Query   | 0    |       | show
processlist |
+-------+------+-----------+------+---------+------+-------
+------------------+


The 3 threads just sit there sleeping, and the time eventually gets to
around 120 seconds before they are terminated and the page finally
loads.

Im about to refactor to store files on the FS, but i cant help but
think that using readfile will cause it to happen less often (possibly
never) but it wont fix what ever is actually happening, just a little
speculation on my part.

Im confident proper caching & faster page loads will prevent the
problem from happening, but i really would like to know whats causing
it.

Phill

On Sep 12, 2:50 am, abba bryant <[EMAIL PROTECTED]> wrote:
> How about starting where we said to start. Serving binary data from the DB is
> a very specific and resource intensive 'need' - so specific in fact that in
> 9.5 years of web development I have NEVER had to do it.
>
> Also, checking the information that AD told you to check out would be a good
> idea.. and the previous hint to post code so someone might be able to point
> out what might be a totally different issue somewhere else in your source...
>
> gearb0x wrote:
>
> > Ive never had this problem before on other apps where i have used
> > similar techniques, and if i wait for the whole page to load before i
> > make the second request everything takes less than a second. I really
> > have no idea where to start :S
>
> > On Sep 11, 1:43 pm, abba bryant <[EMAIL PROTECTED]> wrote:
> >> My guess would be that outputting binary blobs through a script ( meanign
> >> an
> >> http request, a db request, a second http request + output ) for each
> >> image
> >> is simply taking a long time.
>
> >> I wouldn't be surprised if outputting binary data like images was in some
> >> fashion a synchronous event either by design or by virtue of there being
> >> too
> >> few spare cpu cycles to handle a great deal of them.
>
> >> I might also be totally wrong, I can't be sure without some sort of
> >> example
> >> site or code.
>
> >> gearb0x wrote:
>
> >> > Hey guys,
>
> >> > Ive had a similar problem to this on an unrelated cake project before
> >> > (unrelated other than being programed by me as pointed out by someone
> >> > on IRC last night :P)
>
> >> > Whats happening is if i don't let a page load 100% before i click a
> >> > link on it cake will take 1min+ to answer the requests. I cant
> >> > replicate this on my dev environment, i believe its just because the
> >> > pages load too quick (compared to a slow connection over the internet)
>
> >> > A little background on my app:
>
> >> > Any configurable images are stored in the db (i don't need anyone
> >> > telling me this is wrong) so as such, when loading a page with lots of
> >> > images stored in the DB, there are lots of requests going to the
> >> > server for cake stuff. there is a site search page which just sends a
> >> > query string to the index action that filters the data, then you can
> >> > view the sites details
>
> >> > The problem:
> >> > If i click search, then click a site detail link BEFORE the page has
> >> > 100% loaded (images etc). The server appears to hang. I thought it was
> >> > the server crashing but after waiting long enough the site loads fine.
> >> > Ive replicated the problem on my server and used live http headers to
> >> > capture them, you can see the times of the requests from the replys:
>
> >> > http://***.***.***.***/.dev/gpts/city-of-monash/sites/index?q=&x=6&y=6
>
> >> > GET /.dev/gpts/city-of-monash/sites/index?q=&x=6&y=6 HTTP/1.1
> >> > Host: ***.***.***.***
> >> > User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
> >> > 1.8.1.6) Gecko/20070725 Firefox/2.0.0.6
> >> > Accept: text/xml,application/xml,application/xhtml+xml,text/
> >> > html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
> >> > Accept-Language: en-us,en;q=0.7,zh;q=0.3
> >> > Accept-Encoding: gzip,deflate
> >> > Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> >> > Keep-Alive: 300
> >> > Connection: keep-alive
> >> > Referer: http://***.***.***.***/.dev/gpts/city-of-monash/sites/search
> >> > Cookie: CAKEPHP=be8ffe7fcc1167c98d43f0d139f09456
>
> >> > HTTP/1.x 200 OK
> >> > Date: Tue, 11 Sep 2007 02:23:59 GMT
> >> > Server: Apache/2.0.52 (Red Hat)
> >> > X-Powered-By: PHP/4.3.9
> >> > P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
> >> > Content-Type: text/html; charset=UTF-8
> >> > X-Cache: MISS from proxy.cbr.infinite.net.au
> >> > Via: 1.0 proxy.cbr.infinite.net.au:3128 (squid/2.6.STABLE14)
> >> > Connection: close
> >> > ----------------------------------------------------------
> >> > http://***.***.***.***/.dev/gpts/photos/view/19
>
> >> > GET /.dev/gpts/photos/view/19 HTTP/1.1
> >> > Host: ***.***.***.***
> >> > User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
> >> > 1.8.1.6) Gecko/20070725 Firefox/2.0.0.6
> >> > Accept: image/png,*/*;q=0.5
> >> > Accept-Language: en-us,en;q=0.7,zh;q=0.3
> >> > Accept-Encoding: gzip,deflate
> >> > Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> >> > Keep-Alive: 300
> >> > Connection: keep-alive
> >> > Referer:
> >> > http://***.***.***.***/.dev/gpts/city-of-monash/sites/index?q=&x=6&y=6
> >> > Cookie: CAKEPHP=be8ffe7fcc1167c98d43f0d139f09456
>
> >> > HTTP/1.x 200 OK
> >> > Date: Tue, 11 Sep 2007 02:24:00 GMT
> >> > Server: Apache/2.0.52 (Red Hat)
> >> > X-Powered-By: PHP/4.3.9
> >> > P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
> >> > Content-Length: 31359
> >> > content-disposition: inline; filename="headerTEST2.jpg"
> >> > Content-Description: PHP Generated Data
> >> > Content-Type: image/jpeg
> >> > X-Cache: MISS from proxy.cbr.infinite.net.au
> >> > Via: 1.0 proxy.cbr.infinite.net.au:3128 (squid/2.6.STABLE14)
> >> > Connection: keep-alive
> >> > ----------------------------------------------------------
> >> > http://***.***.***.***/.dev/gpts/city-of-monash/photos/view/1
>
> >> > GET /.dev/gpts/city-of-monash/photos/view/1 HTTP/1.1
> >> > Host: ***.***.***.***
> >> > User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
> >> > 1.8.1.6) Gecko/20070725 Firefox/2.0.0.6
> >> > Accept: image/png,*/*;q=0.5
> >> > Accept-Language: en-us,en;q=0.7,zh;q=0.3
> >> > Accept-Encoding: gzip,deflate
> >> > Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> >> > Keep-Alive: 300
> >> > Connection: keep-alive
> >> > Referer:
> >> > http://***.***.***.***/.dev/gpts/city-of-monash/sites/index?q=&x=6&y=6
> >> > Cookie: CAKEPHP=be8ffe7fcc1167c98d43f0d139f09456
>
> >> > HTTP/1.x 200 OK
> >> > Date: Tue, 11 Sep 2007 02:24:00 GMT
> >> > Server: Apache/2.0.52 (Red Hat)
> >> > X-Powered-By: PHP/4.3.9
> >> > P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
> >> > Content-Length: 23408
> >> > content-disposition: inline; filename="Monash_logo.jpg"
> >> > Content-Description: PHP Generated Data
> >> > Content-Type: image/jpeg
> >> > X-Cache: MISS from proxy.cbr.infinite.net.au
> >> > Via: 1.0 proxy.cbr.infinite.net.au:3128 (squid/2.6.STABLE14)
> >> > Connection: keep-alive
> >> > ----------------------------------------------------------
> >> > http://***.***.***.***/.dev/gpts/city-of-monash/sites/view/2
>
> >> > GET /.dev/gpts/city-of-monash/sites/view/2 HTTP/1.1
> >> > Host: ***.***.***.***
> >> > User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
> >> > 1.8.1.6) Gecko/20070725 Firefox/2.0.0.6
> >> > Accept: text/xml,application/xml,application/xhtml+xml,text/
> >> > html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
> >> > Accept-Language: en-us,en;q=0.7,zh;q=0.3
> >> > Accept-Encoding: gzip,deflate
> >> > Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> >> > Keep-Alive: 300
> >> > Connection: keep-alive
> >> > Referer:
> >> > http://***.***.***.***/.dev/gpts/city-of-monash/sites/index?q=&x=6&y=6
> >> > Cookie: CAKEPHP=be8ffe7fcc1167c98d43f0d139f09456
>
> >> > HTTP/1.x 200 OK
> >> > Date: Tue, 11 Sep 2007 02:24:01 GMT
> >> > Server: Apache/2.0.52 (Red Hat)
> >> > X-Powered-By: PHP/4.3.9
> >> > P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
> >> > Content-Type: text/html; charset=UTF-8
> >> > X-Cache: MISS from proxy.cbr.infinite.net.au
> >> > Via: 1.0 proxy.cbr.infinite.net.au:3128 (squid/2.6.STABLE14)
> >> > Connection: close
> >> > ----------------------------------------------------------
> >> > http://***.***.***.***/.dev/gpts/photos/view/19
>
> >> > GET /.dev/gpts/photos/view/19 HTTP/1.1
> >> > Host: ***.***.***.***
> >> > User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
> >> > 1.8.1.6) Gecko/20070725 Firefox/2.0.0.6
> >> > Accept: image/png,*/*;q=0.5
> >> > Accept-Language: en-us,en;q=0.7,zh;q=0.3
> >> > Accept-Encoding: gzip,deflate
> >> > Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> >> > Keep-Alive: 300
> >> > Connection: keep-alive
> >> > Referer: http://***.***.***.***/.dev/gpts/city-of-monash/sites/view/2
> >> > Cookie: CAKEPHP=be8ffe7fcc1167c98d43f0d139f09456
>
> >> > HTTP/1.x 200 OK
> >> > Date: Tue, 11 Sep 2007 02:26:02 GMT
> >> > Server: Apache/2.0.52 (Red Hat)
> >> > X-Powered-By: PHP/4.3.9
> >> > P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
> >> > Content-Length: 31359
> >> > content-disposition: inline; filename="headerTEST2.jpg"
> >> > Content-Description: PHP Generated Data
> >> > Content-Type: image/jpeg
> >> > X-Cache: MISS from proxy.cbr.infinite.net.au
> >> > Via: 1.0 proxy.cbr.infinite.net.au:3128 (squid/2.6.STABLE14)
> >> > Connection: keep-alive
> >> > ----------------------------------------------------------
> >> > http://***.***.***.***/.dev/gpts/city-of-monash/photos/view/1
>
> >> > GET /.dev/gpts/city-of-monash/photos/view/1 HTTP/1.1
> >> > Host: ***.***.***.***
> >> > User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
> >> > 1.8.1.6) Gecko/20070725 Firefox/2.0.0.6
> >> > Accept: image/png,*/*;q=0.5
> >> > Accept-Language: en-us,en;q=0.7,zh;q=0.3
> >> > Accept-Encoding: gzip,deflate
> >> > Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
> >> > Keep-Alive: 300
> >> > Connection: keep-alive
> >> > Referer: http://***.***.***.***/.dev/gpts/city-of-monash/sites/view/2
> >> > Cookie: CAKEPHP=be8ffe7fcc1167c98d43f0d139f09456
>
> >> > HTTP/1.x 200 OK
> >> > Date: Tue, 11 Sep 2007 02:26:02 GMT
> >> > Server: Apache/2.0.52 (Red Hat)
> >> > X-Powered-By: PHP/4.3.9
> >> > P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"
> >> > Content-Length: 23408
> >> > content-disposition: inline; filename="Monash_logo.jpg"
> >> > Content-Description: PHP Generated Data
> >> > Content-Type: image/jpeg
> >> > X-Cache: MISS from proxy.cbr.infinite.net.au
> >> > Via: 1.0 proxy.cbr.infinite.net.au:3128 (squid/2.6.STABLE14)
> >> > Connection: keep-alive
> >> > ----------------------------------------------------------
>
> >> > Hopefully you can see the times in the headers in all that crap. As
> >> > you can see the call to /sites/index & the pictures linked from that
> >> > page are loaded instantly according to the headers. But in my browser
> >> > i click the /sites/view/2 link before the page fully loads, the
> >> > headers say it happens instantly. But if you look at the times
>
> ...
>
> read more >>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to