All Products
Search
Document Center

Function Compute:How do I add or remove built-in extensions to or from the PHP runtime?

Last Updated:Apr 28, 2024

Common extensions are built in the PHP runtime of Function Compute. The built-in extensions can be added or removed based on your business requirements. This topic describes how to add or remove a built-in extension to or from the PHP runtime.

This topic describes how to remove a built-in extension from the PHP runtime environment. In this example, the protobuf built-in extension is removed. For more information about the built-in extensions supported by the Function Compute PHP runtime, see Built-in PHP packages.

  1. Create the extension directory in the same directory as the function entry file. The following sample code describes the directory structure:

    .
    |____extension
    | |____my_ext.ini
    |____index.php
  2. Edit the my_ext.ini file and comment out the protobuf extension.

    You can add extensions or comment on unnecessary extensions to optimize the startup speed of the PHP runtime. Sample code:

    extension=session.so
    extension=ftp.so
    extension=shmop.so
    extension=bcmath.so
    extension=gettext.so
    extension=pcntl.so
    extension=simplexml.so
    extension=xmlreader.so
    extension=bz2.so
    extension=gmp.so
    extension=pdo.so
    extension=soap.so
    extension=xmlrpc.so
    extension=calendar.so
    extension=iconv.so
    extension=pdo_mysql.so
    extension=sockets.so
    extension=xmlwriter.so
    extension=ctype.so
    extension=imagick.so
    extension=phar.so
    extension=sysvmsg.so
    extension=dom.so
    extension=json.so
    extension=posix.so
    extension=sysvsem.so
    extension=exif.so
    extension=zip.so
    extension=memcached.so
    extension=mbstring.so
    ;extension=protobuf.so
    extension=sysvshm.so
    extension=fileinfo.so
    extension=mysqli.so
    extension=redis.so
    extension=tokenizer.so
    extension=zip.so
    extension=memcached.so
    zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20170718/opcache.so
    zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20170718/xdebug.so
  3. Create a function based on the code package in the preceding directory. For more information, see Create a function.

  4. Configure the environment variables for the function. PHP_INI_SCAN_DIR points to my_ext.ini under the code directory. The PHP runtime no longer loads the protobuf extension. PHP_INI_SCAN_DIR