目的
- CentOS8でZephirの開発をする
- 普通のPHP拡張モジュールはCで書く
- 文字列操作が複雑
- メモリ管理が煩雑
- PHP拡張モジュール独自の要素もある
- ZephirはPHP拡張モジュール開発専用言語
- PHPライクな記法
- PHPの関数をそのまま使える
- メモリも文字列も自由に書ける
- 主にclass作成用で、OPCacheのようにエンジンの置き換えはできない?
- 普通のPHP拡張モジュールはCで書く
公式ドキュメント
Zephir Documentation v0.12
github:zephir
どんな環境を作るの?
- OS
- CentOS8
- PHP
- PHP7.2.11
- httpサーバ
- Apache
コピペでできるインストール手順
必要なパッケージのインストール
dnf install -y git gcc gcc-c++ make autoconf automake zip unzip wget tar httpd
re2c
cd /usr/local/src
wget https://github.com/skvadrik/re2c/releases/download/1.3/re2c-1.3.tar.xz
tar Jxfv re2c-1.3.tar.xz
cd re2c-1.3
./configure
make
make install
re2c -v
PHP7
dnf install -y php php-*
php -v
php-zephir-parser
cd /usr/local/src
git clone git://github.com/phalcon/php-zephir-parser.git
cd php-zephir-parser
phpize
./configure
make
make install
vi /etc/php.d/50-php-zephir-parser.ini
[Zephir Parser]
extension=zephir_parser.so
php -m
composer
cd /usr/local/src
curl -sS https://getcomposer.org/installer | php
cp /usr/local/src/composer.phar /usr/local/bin/composer
composer --version
zephir
cd /usr/local/src
git clone --depth 1 -b $(git ls-remote https://github.com/phalcon/zephir 0.12.16 | sort -t/ -k3 -Vr | head -n1 | awk -F/ '{ print $NF }') https://github.com/phalcon/zephir
cd zephir
composer install
vi /etc/profile
export PATH=$PATH:/usr/local/src/zephir
source /etc/profile
再起動
reboot
開発手順
プロジェクト作成
zephir init [任意のモジュール名]
cd [任意のモジュール名]
ソース配置
vi [任意のモジュール名]/[任意のクラス名].zep
namespace [任意のモジュール名(キャメルケース)];
class [任意のクラス名(キャメルケース)]
{
public static function say()
{
echo "hello world!";
}
}
設定変更
vi config.json
internal-call-transformation: true
モジュール登録
vi /etc/php.d/[任意のモジュール名].ini
; Enable [任意のモジュール名] extension module
extension=[任意のモジュール名]
php -m
コンパイル
zephir fullclean
zephir build
systemctl restart php-fpm
使い方
<?php
echo [任意のモジュール名]\[任意のクラス名(キャメルケース)]::say();
?>