phpvips

php libvips: memory leak and GLib errors


I have a server running Ubuntu 22.04 where I have apache and php installed. I have recently started using libvips for php, and I have noticed that every time a php script is run, the amount of ram used increases more and more. For example, if the free ram is 15000 MB, after running the script dozens of times (not simultaneously), the free ram drops to 5000 MB, without being freed.

php file example:

<?php
require __DIR__ . '/vendor/autoload.php';
use Jcupitt\Vips;

$image = Vips\Image::newFromFile($inputImagePath);
$image = $image->thumbnail_image($width, ['height' => $height, 'crop' => 'centre']);
$image->writeToFile($outputImagePath, ['Q' => $quality]);

Instead if at the end of the file i call the function Vips\Config::shutDown(); the memory is released.

Also sometimes libvips returns an error:

(process:211949): GLib-GObject-WARNING **: 16:54:47.542: cannot register existing type 'VipsObject'

(process:211949): GLib-CRITICAL **: 16:54:47.542: g_once_init_leave: assertion 'result != 0' failed

(process:211949): GLib-GObject-CRITICAL **: 16:54:47.542: g_type_register_static: assertion 'parent_
type > 0' failed

(process:211949): GLib-CRITICAL **: 16:54:47.542: g_once_init_leave: assertion 'result != 0' failed

libvips42 version: 8.12.1, php-vips version: 2.0.3


Solution

  • libvips 8.13 resolved these issues.

    See: https://github.com/libvips/php-vips/issues/149