Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Agent Mode for Gemini added to Android Studio

      June 24, 2025

      Google’s Agent2Agent protocol finds new home at the Linux Foundation

      June 23, 2025

      Decoding The SVG path Element: Curve And Arc Commands

      June 23, 2025

      This week in AI dev tools: Gemini 2.5 Pro and Flash GA, GitHub Copilot Spaces, and more (June 20, 2025)

      June 20, 2025

      Microsoft is reportedly planning yet more major cuts at Xbox — as early as next week

      June 24, 2025

      Microsoft makes Windows 10 security updates FREE for an extra year — but there’s a catch, and you might not like it

      June 24, 2025

      “Deus Ex” just turned 25 years old and it’s still the best PC game of all time — you only need $2 to play it on practically anything

      June 24, 2025

      Where to buy a Meta Quest 3S Xbox Edition — and why it’s a better bargain than the “normal” Meta Quest 3S

      June 24, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Vite 7.0 Is Out

      June 24, 2025
      Recent

      Vite 7.0 Is Out

      June 24, 2025

      Exploring JavaScript ES2025 Edition

      June 24, 2025

      Mastering Mixed DML Operations in Apex

      June 24, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft is reportedly planning yet more major cuts at Xbox — as early as next week

      June 24, 2025
      Recent

      Microsoft is reportedly planning yet more major cuts at Xbox — as early as next week

      June 24, 2025

      Microsoft makes Windows 10 security updates FREE for an extra year — but there’s a catch, and you might not like it

      June 24, 2025

      “Deus Ex” just turned 25 years old and it’s still the best PC game of all time — you only need $2 to play it on practically anything

      June 24, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: The Big Pictures

    CodeSOD: The Big Pictures

    May 6, 2025

    Loading times for web pages is one of the key metrics we like to tune. Users will put up with a lot if they feel like they application is responsive. So when Caivs was handed 20MB of PHP and told, “one of the key pages takes like 30-45 seconds to load. Figure out why,” it was at least a clear goal.

    Combing through that gigantic pile of code to try and understand what was happening was an uphill battle. Eventually, Caivs just decided to check the traffic logs while running the application. That highlighted a huge spike in traffic every time the page loaded, and that helped Caivs narrow down exactly where the problem was.

    $first_image = '';
    foreach($images as $the_image)
    { 
        $image = $the_image['url'];
     
      if(file_exists($config->base_url.'/uploads/'.$image))
      {
        if($first_image=='')
        {
          $first_image = $image;
        }
       
        $image_dimensions = '&w=648&h=432';
        $get_dimensions = getimagesize('http://old.datacenter.ip.address/'.$config->base_url.'/uploads/'.$image);
        if($get_dimensions[0] < $get_dimensions[1])
          $image_dimensions = '&h=432';
    
        echo '<li>'.$config->base_url.'/timthumb.php?src='.$config->base_url.'/uploads/'.$image.'&w=125&h=80&zc=1'), 'javascript:;', array('onclick'=>'$('.image_gallery .feature .image').html(''.$config->base_url.'/timthumb.php?src='.$config->base_url.'/uploads/'.$image.$image_dimensions.'&zc=1').'');$('.image_gallery .feature .title').show();$('.image_gallery .feature .title').html("'.str_replace('"', '', $the_image['Image Description']).'");$('.image_gallery .bar ul li a').removeClass('active');$('.image_gallery .bar ul li').removeClass('active');$(this).addClass('active');$(this).parents('li').addClass('active');sidebarHeight();curImg=$(this).attr('id');translate()','id'=>$img_num)).'</li>';
        $img_num++;
      }
    }
    

    For every image they want to display in a gallery, they echo out a list item for it, which that part makes sense- more or less. The mix of PHP, JavaScript, JQuery, and HTML tags is ugly and awful and I hate it. But that’s just a prosaic kind of awful, background radiation of looking at PHP code. Yes, it should be launched into the Kupier belt (it doesn’t deserve the higher delta-V required to launch it into the sun), but that’s not why we’re here.

    The cause of the long load times was in the lines above- where for each image, we getimagesize– a function which downloads the image and checks its stats, all so we can set $image_dimensions. Which, presumably, the server hosting the images uses the query string to resize the returned image.

    All this is to check- if the height is greater than the width we force the height to be 432 pixels, otherwise we force the whole image to be 648×432 pixels.

    Now, the server supplying those images had absolutely no caching, so that meant for every image request it needed to resize the image before sending. And for reasons which were unclear, if the requested aspect ratio were wildly different than the actual aspect ratio, it would also sometimes just refused to resize and return a gigantic original image file. But someone also had thought about the perils of badly behaved clients downloading too many images, so if a single host were requesting too many images, it would start throttling the responses.

    When you add all this up, it meant that this PHP web application was getting throttled by its own file server, because it was requesting too many images, too quickly. Any reasonable user load hitting it would be viewed as an attempted denial of service attack on the file hosting backend.

    Caivs was able to simply remove the check on filesize, and add a few CSS rules which ensured that files in the gallery wouldn’t misbehave terribly. The performance problems went away- at least for that page of the application. Buried in that 20MB of PHP/HTML code, there were plenty more places where things could go wrong.

    [Advertisement]
    Utilize BuildMaster to release your software with confidence, at the pace your business demands. Download today!

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleQuantum Systems raises €160M for AI-powered aerial intelligence
    Next Article TEKEVER becomes the latest unicorn in Europe’s defencetech industry

    Related Posts

    News & Updates

    Microsoft is reportedly planning yet more major cuts at Xbox — as early as next week

    June 24, 2025
    News & Updates

    Microsoft makes Windows 10 security updates FREE for an extra year — but there’s a catch, and you might not like it

    June 24, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    CVE-2023-47029 – NCR Terminal Handler Remote Code Execution and Information Disclosure

    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-4921 – Firefox JavaScript Out-of-Bounds Access Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    FIN6 Uses AWS-Hosted Fake Resumes on LinkedIn to Deliver More_eggs Malware

    Development

    CVE-2025-49144 – Notepad++ Privilege Escalation Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    How to Budget Smartly for Your First AI Project: A Step-by-Step Guide

    May 2, 2025

    Post Content Source: Read More 

    CVE-2025-47713 – Apache CloudStack Domain Admin Privilege Escalation Vulnerability

    June 10, 2025

    CVE-2025-3983 – AMTT Hotel Broadband Operation System NLog Down.php Remote Command Injection Vulnerability

    April 27, 2025

    Not Rumor Anymore: Persona 4 Revival Announced At Xbox Games Showcase 2025

    June 10, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.