Help Center/ FunctionGraph/ devg/ PHP/ Creating a Dependency
Updated on 2024-11-11 GMT+08:00

Creating a Dependency

You are advised to create function dependencies in Huawei Cloud EulerOS 2.0. If other OSs are used, an error may occur due to underlying dependent libraries. For example, the dynamic link library cannot be found.

  • If the modules to be installed need dependencies such as .dll, .so, and .a, archive them to a .zip package.

Creating a Dependency for a PHP Function

EulerOS 2.9.6 is recommended.

By default, Composer and PHP 7.3 have been installed in the environment. Install Protobuf 3.19 using Composer.

Create the composer.json file with the following content:
{
    "require": {
        "google/protobuf": "^3.19"
    }
}
Run the following command:
Composer install

The vendor folder is generated with the autoload.php, composer, and google subfolders in the current directory.

  • Linux

    Run the following command to generate a ZIP package.

    zip –rq vendor.zip vendor
  • Windows

    Compress vendor into a ZIP file.

    If multiple dependencies need to be installed, specify them in the composer.json file, compress the vendor folder into a ZIP file and upload it.

To use third-party dependencies downloaded using Composer in PHP project code, load the dependencies through require "./vendor/autoload.php". By default, files decompressed from the uploaded ZIP package are placed in a directory at the same level as the project code.