Dependencies for PHP functions¶
This section describes how to create dependencies for PHP functions in FunctionGraph.
Example¶
Before creating a dependency, ensure that PHP matching the function runtime has been installed in the environment.
The following uses PHP 8.3 as an example to describe how to create a fg_events dependency package.
Create a directory for your function and navigate to it.
# Create a directory for your function mkdir dependency-fg-events cd dependency-fg-events
Create a composer.json file and add dependencies.
{ "name": "opentelekomcloud-community/dependency-fg-events-php", "description": "FunctionGraph dependency FG events for PHP", "type": "library", "license": "Apache-2.0", "require": { "opentelekomcloud-community/otc-functiongraph-php-runtime": "^1.0" }, "archive": { "exclude": [ "Makefile", "terraform", "resources" ] }, "config": { "archive-format": "zip", "sort-packages": true } }
create a Makefile with a create_package target to automate the packaging process.
# create a zip package of the function code for deployment # based on composer.json archive settings create_package: # install production dependencies without development dependencies composer install --no-dev --prefer-dist # create a code.zip archive of the production dependencies composer archive --format=zip --file=vendor # reinstall all dependencies including development dependencies composer install
Create vendor.zip file using
make create_packageDeploy the dependency package to FunctionGraph as described in Configuring Dependency Packages