vip-go-mu-plugins icon indicating copy to clipboard operation
vip-go-mu-plugins copied to clipboard

fix(files): memory usage in `filter_wp_read_image_metadata()`

Open sjinks opened this issue 2 months ago • 4 comments

Description

Reduce memory usage in VIP_Filesystem::filter_wp_read_image_metadata() by using copy() instead of file_get_contents()/file_put_contents().

The symptoms are:

PHP message: PHP Fatal error:  Allowed memory size of 805306368 bytes exhausted (tried to allocate 5046659072 bytes) in /wp/wp-content/mu-plugins/files/class-vip-filesystem.php on line 454

Changelog Description

Fixed

  • Reduced memory consumption in the VIP File Service plugin when retrieving metadata of a large file.

Pre-review checklist

Please make sure the items below have been covered before requesting a review:

  • [x] This change works and has been tested locally or in Codespaces (or has an appropriate fallback).
  • [ ] This change works and has been tested on a sandbox.
  • [ ] This change has relevant unit tests (if applicable).
  • [ ] This change uses a rollout method to ease with deployment (if applicable - especially for large scale actions that require writes).
  • [ ] This change has relevant documentation additions / updates (if applicable).
  • [x] I've created a changelog description that aligns with the provided examples.

Pre-deploy checklist

  • [ ] VIP staff: Ensure any alerts added/updated conform to internal standards (see internal documentation).

Steps to Test

Upload a large file (its size should exceed the memory available to PHP) before and after this patch.

sjinks avatar May 10 '24 00:05 sjinks