LoginSignup
0
0

More than 5 years have passed since last update.

ZephirでPHPExtensionを作ってみる

Posted at

公式マニュアルを参考に。
https://github.com/phalcon/zephir/blob/master/WINDOWS.md
事前にVisual Studio 2015をインストールしている必要があります。

PHP,PHP SDK,PHP Developer Pack,Zephirをインストールする

今回はx86バージョンを使用しています。
PHPディレクトリにPHP SDKPHP Developer PackZephirを配置する。

C:\php-7.2.10-Win32-VC15-x86
C:\php-7.2.10-Win32-VC15-x86\php-sdk
C:\php-7.2.10-Win32-VC15-x86\php-devel-pack
C:\php-7.2.10-Win32-VC15-x86\zephir

Zephir ParserをPHPに組み込む

php_zephir_parser.dllextにコピーして
zephir_parserphp.iniに追加する。

php.ini
extension=zephir_parser

コマンドプロンプトで環境変数を設定する

Winodwsの環境変数に登録しないようにしたいので、必要なパスをコマンドプロンプトから設定する。

# Visual Studio 2015 にパスを通す
set VS140COMNTOOLS="C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\"
call %VS140COMNTOOLS%\VsDevCmd

# PHP,SDK,Develop,Zephirにパスを通す
set PHP_HOME=C:\php-7.2.10-Win32-VC15-x86
set PATH=%PATH%;%PHP_HOME%
set PHP_SDK=%PHP_HOME%\php-sdk
set PHP_DEVPACK=%PHP_HOME%\php-devel-pack
set PATH=%PATH%;%PHP_HOME%\zephir\bin

# SDKの環境変数を設定する
%PHP_SDK%\bin\phpsdk_setvars

これをバッチファイルにまとめておくと便利。

Zephirプロジェクトを作成してビルドする

zephir initでプロジェクトを作成する。

zephir init test

その配下のあるtestフォルダにsample.zepを作成する。

sample.zep
namespace Test;

class Sample
{
    public static function say()
    {
        echo "hello world!";
    }
 }

zephir buildでビルドする。

zephir build

プロジェクトのext\Release_TSにDLLが作成されるので、php.iniextensionを追加する。

php.ini
extension="C:\php-7.2.10-Win32-VC15-x86\test\ext\Release_TS\php_test.dll"

あとは確認用のスクリプトから実行されるかを確認する。

sample.php
<?php
Test\Sample::say();

hello world!が表示されたらok!

>php sample.php
hello world!
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0