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 |
|
|
tablestore |
v4.1.1 |
|
|
mns |
v1.3.5.5 |
Alibaba Cloud Simple Message Queue (formerly MNS) SDK for PHP |
|
fc |
v1.2.1 |
Built-in PHP extensions
Built-in extensions
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
-
Docker is installed. For more information about the procedure, see Step 2: Configure your AccessKey pair.
-
A function that runs in a PHP runtime is created. For more information about the procedure, see Create an event-triggered function.
Procedure
-
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 bashNoteOn Windows, replace
$(pwd)with an absolute directory path. -
Install the MongoDB extension and copy mongodb.so to the /code directory.
-
Install the MongoDB extension:
pecl install mongodb -
Find the MongoDB extension file:
find /usr -name "mongodb.so" -
Copy the extension file to /code:
cp /usr/local/lib/php/extensions/no-debug-non-zts-20170718/mongodb.so /code -
Exit the container:
exit -
Verify that mongodb.so exists in your local directory.
lsExpected output:
mongodb.so
-
Log on to the Function Compute console. In the left-side navigation pane, click Functions.
In the top navigation bar, select a region. On the Functions page, click the function that you want to manage.
-
On the function details page, click the Code tab and create an extension folder in the handler file directory.
NoteThe extension folder must be at the same level as bootstrap.
-
Add mongodb.so to the extension folder and create mongodb.ini in the extension folder.
-
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
-
For more information about how to create a custom extension based on a built-in extension, see Add or remove built-in PHP extensions
-
To install the MongoDB extension in a custom runtime:How to install a custom extension in a custom runtime.