bng
bng

Reputation: 119

How to reduce the size of Google PHP library?

The size of Google php API Library is very large. I just want to send an email with the library. How can I reduce its size?

Upvotes: 12

Views: 3058

Answers (2)

Michael Mitch
Michael Mitch

Reputation: 839

To reduce the vendor library size, google/apiclient offers a configuration on composer.json to run a cleanup script post-update.

This way you can specify only your required apis,
to reduce storage size on production.
Especially if you are going to use it on tighter storage requirement environment, like serverless architecture.

Reference: https://packagist.org/packages/google/apiclient

The required apis specified under "google/apiclient-services", please refer to https://github.com/googleapis/google-api-php-client-services/tree/main/src

{
    "require": {
        "google/apiclient": "^2.7"
    },
    "scripts": {
        "post-update-cmd": "Google\\Task\\Composer::cleanup"
    },
    "extra": {
        "google/apiclient-services": [
            "Drive",
            "YouTube"
        ]
    }
}

for no services at all (for instance you're only using the API to verify the integrity of a JWT ID token) the extra.google/apiclient-services array/list needs to contain an empty string

"extra": {
    "google/apiclient-services": [ "" ]
}

You may want remove the entire apiservices folder first, and then do a composer update, if you already installed a full set of api.

$ rm -r vendor/google/apiclient-services
$ composer update

Upvotes: 13

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 117321

The reason the library is large is that it contains all of the classes for all of the Google Discovery api's i think there are around 120 of them.

The only way i know of to reduce the size is to remove all of the APIs you dont need. check the Google/Service directory. Delete the apis you are not planning on using.

Leave everything else.

There is also the option of

composer install --no-dev

Upvotes: 1

Related Questions