Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to add custom extensions for the PHP runtime

Shulou Source: shulou.com Published: 2022-06-01 02:19:20 09月21日 Update

This article will explain in detail how to add custom extensions to the PHP runtime. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

The PHP language provides an extension mechanism (Extension) through which PHP extensions can enhance syntax, call library functions implemented by Cpicket +, and optimize execution performance. PHP extensions are platform-related dynamic link libraries, .so files on Linux and Mac platforms, and .dll files on Windows platforms. Because the development of function computing is usually on the Mac and Windows platforms, and the runtime is in Linux (Debain) environment, adding extensions to the PHP runtime of function computation will encounter the problem that either the local or the remote end cannot be debugged or run because of the dynamic link library platform. This article introduces the installation, local debugging, build and release of PHP extensions with the help of the simulation environment provided by Funcraft tools.

Preparation depends on tools

This project is developed under MacOS, the tools involved are platform-independent, and should also be applicable to Linux and Windows desktop systems. Before starting this example, make sure that the following tools are installed correctly, updated to the latest version, and configured correctly.

Docker

Fun

The Fun and Fcli tools rely on docker to simulate the local environment.

For MacOS users, you can use homebrew to install:

Brew cask install dockerbrew tap vangie/formulabrew install funbrew install fcli

For Windows and Linux user installation, please refer to:

Https://github.com/aliyun/fun/blob/master/docs/usage/installation.md

Https://github.com/aliyun/fcli/releases

After installation, remember to initialize the configuration by executing fun config first.

Note that if you have already installed fun, make sure that the fun version is above 3.6.1.

$fun-- version3.6.1PHP custom extension

Create a directory called extension in the function code directory and place the .ini and .so files corresponding to the extension in the extension directory. For example, the following is a custom extension of hello, assuming that there is a hello_world function in the extension:

. | _ extension | | _ hello.ini | | _ hello.so | _ main.php

Hello.ini

Extension=/code/extension/hello.so

Main.php

Tags: File directory run function platform tool environment version update configuration code command article system development content dynamic variable copy method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Apple Linux Shulou Information Microsoft