0

I'm developing a plugin and I'm quite new in that, so I trying to find the best solution for how to integrate composer with my plugin.

The problem is that the SDK which I need is quite big, and when I integrate it on the plugin, the plugin has more than 50mb which is very big and some time on the plugin installation it's crashed because it is too big. I'm sending many data from the plugin on the Firebase Realtime database, so I need to use kreait/firebase-php SDK for that.

So, I want to find some solution where I can set only the composer.json file inside the plugin folder and after the plugin activation to pull and install the required SDK.

Here is my composer.json file:

{
    "name": "marko/conn-firebase",
    "description": "desc",
    "type": "project",
    "license": "GNU3",
    "authors": [
        {
            "name": "Marko",
            "email": "test@test.com"
        }
    ],
    "minimum-stability": "dev",
    "require": {
        "kreait/firebase-php": "4.35",
        "php": ">= 7.2.0"
    }
}

Any help is welcomed. Thanks

  • 2
    Do you plan to publish the plugin to the official WordPress SVN? Or is this a plugin for a specific customer/case where you have control over the environment (your own/customer's server that you can SSH into)? – kero Nov 19 at 16:31
1

So, I want to find some solution where I can set only the composer.json file inside the plugin folder and after the plugin activation to pull and install the required SDK.

That's not how it works. Composer is a CLI tool that's meant to be ran via CLI, and wasn't designed to run in a browser request context. If you achieve it, most PHP developers will consider it extreme bad practice.

You're also very likely to swap your current problem for the problem of timeouts, if you can't upload and unzip a single file into a folder in time, then running a CLI command to download multiple zips and write them to folders, and figure out dependencies won't be much better.

If sounds like your actual problem is uploading large zips on the plugin page not working, why not ask about that?

So this is how you handle composer for plugin distribution:

If You're Distributing The Plugin for Sale or to Customers

Run composer install then package up the result

If You're Putting it In Version Control

Don't run composer install, that happens during deployment/downloading


The same is true of npm or any other package management. You don't run composer install or npm install in production, but rather you deploy the result to production.

A final note attempting to answer your actual problem:

You don't need to install the dev dependencies to distribute the plugin. You're likely installing everything from require-dev, and the package you want has PHPUnit and other QA tools listed as its dev dependencies, inflating the size.

Additionall, if you're doing this for development, just install it directly on the filesystem using a local dev environment, and upload the final production build instead of a dev build.

Remove the minimum-stability: dev section or adjust your composer install command to only install things from the require.

  • I've re-installed composer did the changes on the way you told me and now it's perfect. The plugin has less 4mb now. Thank you very much. – batman Nov 19 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.