Do You PHP はてブロ

Do You PHPはてなからはてブロに移動しました

simframeをインストールしてみた

Simplateの配布サイトでSimframeというPHP拡張モジュール(+PHPスクリプト)として作られたフレームワークがあります。

ググっても、ほとんど情報がないですね。で、早速試してみようと。。。悪戦苦闘。結論から先に言うと、

  • インストールは問題なくできる(環境に依る?)
  • DB設定(対象はsqlite)も問題なくできる
  • generatorを使ったController生成でsegfault

で止まってしまいました。。。orz

ネタ的にもったいないので、やった内容を晒しておきます。

環境

インストール

Simframeの配布サイトにある手順のままで問題なくインストールできました。ただし、RPMPHP(5.1.6)を使った場合、「php_pcre.hがない」と怒られました。

# make
           :
 g++ -I. -I/usr/local/src/simframe/extension -DPHP_ATOM_INC -I/usr/local/src/simframe/extension/include -I/usr/local/src/simframe/extension/main -I/usr/local/src/simframe/extension -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -DHAVE_CONFIG_H -c /usr/local/src/simframe/extension/simframe_map.cpp  -fPIC -DPIC -o .libs/simframe_map.o
In file included from /usr/local/src/simframe/extension/simframe_map.cpp:11:
/usr/include/php/ext/pcre/php_pcre.h:29:18: pcre.h: No such file or directory
In file included from /usr/local/src/simframe/extension/simframe_map.cpp:11:
/usr/include/php/ext/pcre/php_pcre.h:45: error: expected constructor, destructor, or type conversion before '*' token
/usr/include/php/ext/pcre/php_pcre.h:46: error: expected constructor, destructor, or type conversion before '*' token
/usr/include/php/ext/pcre/php_pcre.h:52: error: ISO C++ forbids declaration of `pcre' with no type
/usr/include/php/ext/pcre/php_pcre.h:52: error: expected `;' before '*' token
/usr/include/php/ext/pcre/php_pcre.h:53: error: ISO C++ forbids declaration of `pcre_extra' with no type
/usr/include/php/ext/pcre/php_pcre.h:53: error: expected `;' before '*' token
/usr/local/src/simframe/extension/simframe_map.cpp: In function `void zif_simframe_map_parse(int, zval*, zval**, zval*, int)':
/usr/local/src/simframe/extension/simframe_map.cpp:156: error: `pcre' was not declared in this scope
/usr/local/src/simframe/extension/simframe_map.cpp:156: error: `regex' was not declared in this scope
/usr/local/src/simframe/extension/simframe_map.cpp:176: error: `pcre_compile' was not declared in this scope
/usr/local/src/simframe/extension/simframe_map.cpp:180: error: `pcre_exec' was not declared in this scope
make: *** [simframe_map.lo] エラー 1
# 

src版PHP5.1.6の場合は問題なくインストールできました。

動作確認

src版PHP5.2.2の場合、xdebugを入れておくとSimframeに付属するindex.phpにアクセスした段階でsegfaultしました。外すとSimframeの配布サイト]にあるように、DB接続エラーである旨のメッセージが表示されます。

Wrong DB Setting:Check your `database.yml' again.

なお、PDOExceptionのメッセージは表示されないので、適宜index.phpを変更して確認した方が良いです。

     1  <?php
     256        }catch( PDOException $e ){
    57          echo "Wrong DB Setting:Check your `database.yml' again.<br>";
    58          echo "cause : " . $e->getMessage();
    59          exit();
    60        }

sqliteを使う場合、config/database.ymlを

development:
  adapter: sqlite
  database: sampledb
  host:
  username:
  password:

のように変更することになるっぽいですが、DSNが

sqlite:dbname=sampledb;host=

となってしまい、「dbname=sampledb;host=」というファイルが作成されてしまいます。まあ、DSNはindex.phpで作成しているので、何とでもなるかな、と。
database.ymlを変更後、再度index.phpにアクセスすると、

Error Found
No specified Controller:

となり、想定通り動作しているようでした。

generateコマンドでController作成

まあ、ここで止まってしまったわけですが。。。

$ php -q script/generate.php controller Top index
セグメンテーション違反です
$ 

ちょっとだけソースを追ってみましたが、

  script/generate.php
          ↓ [require_once]
script/config_script.php
          ↓ [require_once]
 config/environment.php
          ↓ [require_once]
   config/routes.php

とrequire_onceされていて、

<?php


// default rules
SMap::connect('/:controller/:action/:id');
               :

でsegfaultしているようです。SMapsimframeで用意されている組み込みクラスです。