Help Center/ FunctionGraph/ Developer Guide/ PHP/ Creating a Dependency for a PHP Function
Updated on 2025-12-10 GMT+08:00

Creating a Dependency for a PHP Function

Setting Up the EulerOS Environment

You are advised to create function dependencies in Huawei Cloud EulerOS 2.0. If other OSs are used, the dynamic link library may not be found due to the differences between underlying dependency libraries.

EulerOS is an enterprise-grade Linux OS based on open-source technology. It features high security, scalability, and performance, meeting customers' requirements for IT infrastructure and cloud computing services.

You can set up the Huawei Cloud EulerOS environment using the following methods:

  • Buy a EulerOS ECS on Huawei Cloud by referring to Purchasing and Logging In to a Linux ECS. On the Configure Basic Settings page, select Public Image, and select Huawei Cloud EulerOS and an image version.
  • Download the EulerOS image, and use virtualization software to set up the EulerOS VM on a local PC.

Constraints

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

Before creating a dependency, ensure that PHP matching the function runtime has been installed in the environment. The following uses PHP 7.3 as an example to describe how to install the protobuf3.19 dependency using Composer. Composer has been installed in the default environment. The procedure is the same for other PHP versions.

  1. Create the composer.json file with the following content:

    {
        "require": {
            "google/protobuf": "^3.19"
        }
    }

  2. Run the following command:

    Composer install

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

  3. Run the following command to generate a ZIP package:

    zip –rq vendor.zip vendor

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

In PHP projects, third-party dependencies downloaded using Composer need to be loaded using require "./vendor/autoload.php". By default, FunctionGraph stores the decompressed files in a directory at the same level as the project code directory.