Problem/Motivation

One of our projects is hosted behind a reverse proxy (Squid) that is enforcing a network policy to only allow TCP traffic, and is dropping HTTP traffic. I was experiencing timeouts running the rokka_post_update_generate_missing_thumbnails() which I tracked down to this proxy issue.

The problem is in RokkaMetadataStorage::getImageDimensions(). It uses the ::parseFile() function from the GD toolkit to get image dimensions, but this fails in my situation because it cannot reach the Rokka servers.

Steps to reproduce

When PHP is operated behind a TCP only proxy, it cannot access HTTP resources through the functions from the standard library. For example a simple function like this will fail:

file_get_contents('https://myproject.rokka.io/dynamic/3f5f461dc4dac5d89c01d7a44f89e45e7ce3e630.jpg')

Proposed resolution

A robust practice in PHP for accessing online resources is to use dedicated HTTP clients (like Guzzle) which can handle the TCP protocol directly. You can see this also used in the Rokka PHP library for example. It is using file_get_contents() for accessing local files, but Guzzle for accessing files hosted on Rokka.

The GD toolkit doesn't use Guzzle obviously, but uses the internal PHP functions. The solution is to use the HTTP client for this. This is not a controversial change because we are already using this pattern everywhere else, for example the sister method RokkaMetadataStorage::getFileSize() also uses it for getting the file size. We just need to follow the same pattern.

Remaining tasks

Retrieve the image through the HTTP client instead of through the GD toolkit, before calculating the dimensions.

Issue fork rokka-3576209

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

pfrenssen created an issue. See original summary.

  • pfrenssen committed b77f4163 on 3.x
    feat: #3576209 getImageDimensions() can fail behind proxies
    
    By:...

  • pfrenssen committed b77f4163 on 4.x
    feat: #3576209 getImageDimensions() can fail behind proxies
    
    By:...
pfrenssen’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.