Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php 8.3.4 + laravel-medialibrary 11.4.5: opcache+jit error: Only arrays and Traversables can be unpacked #3568

Open
izica opened this issue Mar 18, 2024 · 2 comments

Comments

@izica
Copy link

izica commented Mar 18, 2024

After turning on opcache+jit, after some time an error occurs:
/var/www/backend/vendor/spatie/laravel-medialibrary/src/InteractsWithMedia.php:607
Only arrays and Traversables can be unpacked

        $preparedMediaConversions = collect($this->mediaConversions)
            ->each(fn (Conversion $conversion) => $conversion->performOnCollections($mediaCollection->name))
            ->values()
            ->toArray();

->     $this->mediaConversions = [...$actualMediaConversions, ...$preparedMediaConversions];
    });
    $this->registerMediaConversions($media);
}

this only happens after some time(5+ mins of requests), when opcache+jit is enabled
in logs
$actualMediaConversions === false (only after opcache+jit)

Code and settings:

zend_extension=opcache.so
opcache.enable=1
opcache.enable_cli=1
opcache.jit_buffer_size=100M
opcache.jit=1235
class Compilation extends BaseCompilation implements HasMedia
{
    use InteractsWithMedia;

    const IMAGE = 'image';

    protected $hidden = [
        self::CREATED_AT,
        self::UPDATED_AT,
        'pivot'
    ];

    protected $fillable = [
        self::NAME,
        self::SLUG,
        self::IMAGE,
        self::AT_HEADER,
    ];

    protected $with = [
        'media'
    ];

    public function registerMediaCollections(): void
    {
        $this->addMediaCollection(self::IMAGE)
            ->singleFile()
            ->useFallbackUrl(
                \Storage::disk(config('disks.assets'))->url('images/dummy.png')
            )
            ->registerMediaConversions(function () {
                $this->addMediaConversion('resized')
                    ->width(400)
                    ->height(400);
            });
    }
}
@izica
Copy link
Author

izica commented Mar 20, 2024

           $this->mediaConversions = [
               ...(is_array($actualMediaConversions) ? $actualMediaConversions : []),
               ...(is_array($preparedMediaConversions) ? $preparedMediaConversions : []),
           ];

Sometimes when opcache+jit is enabled, somehow $actualMediaConversions or $preparedMediaConversions are false, not array.
This happens only with singleFile collections.
I inherited this trait and overridden method with a quick fix.
Perhaps this is happening because I am using methods getRegisteredMediaCollections and getMediaCollection in custom attributes, and this registers the collections on every call $this->registerMediaCollections();

Also I tried to separate conversion to registerMediaConversions method, but the error still repeats.

@izica izica changed the title php 8.3.4 opcache+jit error: Only arrays and Traversables can be unpacked php 8.3.4 + laravel-medialibrary 11.4.5: opcache+jit error: Only arrays and Traversables can be unpacked Mar 20, 2024
@timvandijck
Copy link
Member

Looks hard to reproduce: if anyone is also experiencing this let us know, I'm wondering how many users it's impacting.

I would be happy to accept a PR if something can be improved on our side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants