Cached, PHP generated Thumbnails load slowly

前端 未结 19 2051
醉酒成梦
醉酒成梦 2020-12-12 11:35

Question Part A ▉ (100 bountys, awarded)
Main question was how to make this site, load faster. First we needed to read these waterfalls. Thanks all fo

相关标签:
19条回答
  • 2020-12-12 11:57

    Investigate PHP's usage of session data. Maybe (just maybe), the image-generating PHP script is waiting to get a lock on the session data, which is locked by the still-rendering main page or other image-rendering scripts. This would make all the JavaScript/browser optimizations almost irrelevant, since the browser's waiting for the server.

    PHP locks the session data for every script running, from the moment the session handling starts, to the moment the script finishes, or when session_write_close() is called. This effectively serializes things. Check out the PHP page on sessions, especially the comments, like this one.

    0 讨论(0)
  • 2020-12-12 12:00

    I think instead of using that thumbnail-generator script you must give TinySRC a try for rapid fast and cloud-hosted thumbnail generation. It has a very simple and easy to use API, you can use like:-

    http://i.tinysrc.mobi/ [height] / [width] /http://domain.tld/path_to_img.jpg

    [width] (optional):- This is a width in pixels (which overrides the adaptive- or family-sizing). If prefixed with ‘-’ or ‘x’, it will subtract from, or shrink to a percentage of, the determined size.

    [height] (optional):- This is a height in pixels, if width is also present. It also overrides adaptive- or family-sizing and can be prefixed with ‘-’ or ‘x’.

    You can check the API summary here


    FAQ

    What does tinySrc cost me?

    Nothing.

    When can I start using tinySrc?

    Now.

    How reliable is the service?

    We make no guarantees about the tinySrc service. However, it runs on a major, distributed cloud infrastructure, so it provides high availability worldwide. It should be sufficient for all your needs.

    How fast is it?

    tinySrc caches resized images in memory and in our datastore for up to 24 hours, and it will not fetch your original image each time. This makes the services blazingly fast from the user’s perspective. (And reduces your server load as a nice side-effect.)


    Good Luck. Just a suggestion, since u ain't showing us the code :p

    0 讨论(0)
  • 2020-12-12 12:01

    This is just a wild guess since I haven't looked at your code but I suspect sessions may be playing a role here, the following is from the PHP Manual entry on session_write_close():

    Session data is usually stored after your script terminated without the need to call session_write_close(), but as session data is locked to prevent concurrent writes only one script may operate on a session at any time. When using framesets together with sessions you will experience the frames loading one by one due to this locking. You can reduce the time needed to load all the frames by ending the session as soon as all changes to session variables are done.

    Like I said, I don't know what your code is doing but those graphs seem oddly suspicious. I had a similar issue when I coded a multipart file serving function and I had the same problem. When serving a large file I couldn't get the multipart functionality to work nor could I open another page until the download was completed. Calling session_write_close() fixed both my problems.

    0 讨论(0)
  • 2020-12-12 12:01

    Regarding the delayed thumbnails, try putting a call to flush() immediately after the last call to header() in your thumbnail generation script. Once done, regenerate your waterfall graph and see if the delay is now on the body instead of the headers. If so you need to take a long look at the logic that generates and/or outputs the image data.

    The script that handles the thumbnails should hopefully use some sort of caching so that whatever actions it takes on the images you're serving will only happen when absolutely necessary. It looks like some expensive operation is taking place every time you serve the thumbnails which is delaying any output (including the headers) from the script.

    0 讨论(0)
  • 2020-12-12 12:02

    First, using those multiple domains requires several DNS lookups. You'd be better off combining many of those images into a sprite instead of spreading the requests.

    Second, when I load your page, I see most of the blocking (~1.25s) on all.js. I see that begins with (an old version of) jQuery. You should reference that from the Google CDN, to not only decrease load time, but potentially avoid an HTTP request for it entirely.

    Specifically, the most current jQuery and jQuery UI libraries can be referenced at these URLs (see this post if you're interested why I omitted the http:):

    //ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js
    
    //ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js
    

    If you're using one of the default jQuery UI themes, you can also pull its CSS and images off the Google CDN.

    With the jQuery hosting optimized, you should also combine awmlib2.js and tooltiplib.js into a single file.

    If you address those things, you should see a significant improvement.

    0 讨论(0)
  • 2020-12-12 12:02

    Just a simple guess because this kind of analysis requires a lot of A/B testing: your .ch domain seems to be hard to reach (long, green bands before the first byte arrives).

    This would mean that either the .ch website is poorly hosted or that you ISP does not have a good route to them.

    Given the diagrams, this could explain a big performance hit.

    On a side note, there is this cool tool cuzillion that could help you sort out things depending on your ordering of ressource loading.

    0 讨论(0)
提交回复
热议问题