All Products
Search
Document Center

Function Compute:PHP

Last Updated:Jun 02, 2026

Learn about the PHP runtimes, built-in packages, and extensions that Function Compute supports.

PHP runtimes

The following PHP runtimes are supported by Function Compute.

Version

Operating system

Architecture

PHP 7.2

Linux

x86_64

Built-in PHP packages

The PHP runtime includes the following built-in packages.

Package

Version

Reference

oss

v2.4.3

Alibaba Cloud OSS SDK for PHP

tablestore

v4.1.1

Alibaba Cloud TableStore SDK for PHP

mns

v1.3.5.5

Alibaba Cloud Simple Message Queue (formerly MNS) SDK for PHP

fc

v1.2.1

Alibaba Cloud Function Compute SDK for PHP

Built-in PHP extensions

Built-in extensions

Note

To list installed extensions, add print_r(get_loaded_extensions()); to your function code.

bcmath

bz2

calendar

Core

ctype

curl

date

dom

exif

fileinfo

filter

ftp

gd

gettext

gmp

hash

iconv

imagick

json

libxml

mbstring

memcached

mysqli

mysqlnd

openSSL

pcntl

pcre

PDO

pdo_mysql

Phar

posix

protobuf

readline

redis

Reflection

session

shmop

SimpleXML

soap

sockets

SPL

standard

sysvmsg

sysvsem

sysvshm

tokenizer

Xdebug

xml

xmlreader

xmlrpc

xmlwriter

Zend OPcache

zip

zlib

None

None

Built-in extension example

This example uses json to parse a JSON string and print the result:

<?php
function handler($event, $context) {
    var_dump(json_decode('{"a":123, "b":true, "c":"abcd", "d":{"a":123}}', true));
    return "bye";
}         

Install non-built-in PHP extensions

The following steps show how to install a non-built-in PHP extension, using MongoDB as an example.

Prerequisites

Procedure

  1. Run the following command from your project directory to start the PHP runtime container and mount the current directory to /code:

    sudo docker run -v $(pwd):/code -it --entrypoint=""  registry.cn-beijing.aliyuncs.com/aliyunfc/runtime-php7.2:latest  bash
    Note

    On Windows, replace $(pwd) with an absolute directory path.

  2. Install the MongoDB extension and copy mongodb.so to the /code directory.

    1. Install the MongoDB extension:

      pecl install mongodb
    2. Find the MongoDB extension file:

      find /usr -name "mongodb.so"
    3. Copy the extension file to /code:

      cp /usr/local/lib/php/extensions/no-debug-non-zts-20170718/mongodb.so /code
    4. Exit the container:

      exit
    5. Verify that mongodb.so exists in your local directory.

      ls

      Expected output:

      mongodb.so
  3. Log on to the Function Compute console. In the left-side navigation pane, click Functions.

  4. In the top navigation bar, select a region. On the Functions page, click the function that you want to manage.

  5. On the function details page, click the Code tab and create an extension folder in the handler file directory.

    Note

    The extension folder must be at the same level as bootstrap.

  6. Add mongodb.so to the extension folder and create mongodb.ini in the extension folder.

  7. Edit the mongodb.ini file.

    Add the following line to mongodb.ini:

    extension=/code/extension/mongodb.so

Download files for other custom extensions:

Additional information