Upload
yohei-sato
View
2.249
Download
2
Embed Size (px)
Citation preview
Yohei Sato 1
初めての PHP Extension
id:yokkuns 里 洋平
PHP カンファレンス 2009
Yohei Sato 2
アジェンダ● 自己紹介● PHP Extension とは● 引数と返り値● PHP の内部構造● PHP Extension の作成
Yohei Sato 3
自己紹介● id:yokkuns● 名前 : 里 洋平● 職業 :Web エンジニア● 出身 : 種子島● 趣味 : プログラミングとかカラオケとか● 仕事は、 PHP では無く、 Perl
Yohei Sato 4
PHP Extension とは?
Yohei Sato 5
PHP Extension とは● PHP の拡張モジュール● C/C++ で書かれてる● 例) mysql 、 sockets 、 SimpleXML など
Yohei Sato 6
何故 PHP Extension ?● 過去に C で書かれた既存のライブラリを流用したい
● 実行速度。 C なので、当然 PHP で書くより速い。
Yohei Sato 7
引数と返り値
Yohei Sato 8
Extension で行う処理● 引数の取得● データ作成処理● 返り値の出力
Yohei Sato 9
データ型の問題● そのままでは、データのやりとりが出来ない。
$a$a = 100
Yohei Sato 10
データ型の問題● そのままでは、データのやりとりが出来ない。
a
int a = 100
Yohei Sato 11
そこで、 Zend API
ZendAPI
$a
$a = 100
long a
a == 100
Yohei Sato 12
そこで、 Zend API
ZendAPI
$a
$a == 100
a
long a =100
Yohei Sato 13
PHP の内部構造
Yohei Sato 14
zval 構造体
zval構造体
value refcount type is_ref
$a = 100
Yohei Sato 15
zval 構造体
zval構造体
value refcount type is_ref
$a = 100
type = IS_LONG
Yohei Sato 16
zval 構造体
zval構造体
value refcount type is_ref
$a = 100
zvalue_value共用体
lval dval str ht objtype = IS_LONG
Yohei Sato 17
zval 構造体
zval構造体
value refcount type is_ref
$a = 100
zvalue_value共用体
lval dval str ht obj
100
type = IS_LONG
Yohei Sato 18
文字列の場合
zval構造体
value refcount type is_ref
$a = "PHP"
zvalue_value共用体
lval dval str ht obj
type = IS_STRING
str構造体
val len
PHP3
Yohei Sato 19
PHP のデータタイプ● IS_NULL
● IS_LONG
● IS_DOUBLE
● IS_BOOL
● IS_ARRAY
● IS_OBJECT
● IS_STRING
● IS_RESOURCE
● IS_CONSTANT
● IS_CONSTANT_ARRAY
Yohei Sato 20
PHP の配列● PHP の配列は、 C とかで言う配列とは別物● 順番付けられたマップ
Yohei Sato 21
PHP の配列の構造
zval
type = IS_ARRAY
zvalue_value
a
b
c
zval
zval
zval
hashtable
Yohei Sato 22
PHP のオブジェクトの構造
zval
type = IS_OBJECT
zvalue_value zend_object_value構造体
handle handlers zend_object_handlers
構造体
Yohei Sato 23
zend_object_handlerszend_object_handlers
add_ref del_ref delete_obj clone_obj read_property write_property get_property_ptr get_property_zval_ptr get set has_property unsert_property get_properties get_method call_method get_constructor get_class_entry get_class_name compare_objects
Yohei Sato 24
PHP Extension の作成
Yohei Sato 25
PHP Extension 作成方法● 昔は、 ext_skel コマンド
– スケルトンを生成し、それを直接修正
● 今は、 CodeGen_PECL– XML ファイルから PECL 用のコードを生成
Yohei Sato 26
CodeGen_PECL を使ってExtension を作成
Yohei Sato 27
・・・と思ったんですが
Yohei Sato 28
何と時間が無い!
Yohei Sato 29
と、言うわけで続きは、次回やります!
Yohei Sato 30
ご清聴ありがとうございました。
Yohei Sato 31
参考サイト● PHP: Zend API: PHP のコアをハックする - Manual
– http://www.php.net/manual/ja/internals2.ze1.zendapi.php
● PHP 変数管理を理解する - CPA-LAB テクニカル
– http://www.cpa-lab.com/tech/032
● DSAS 開発者の部屋 :PHP Extension を作ろう第1回 - まずは Hello World
– http://dsas.blog.klab.org/archives/50777398.html
● DSAS 開発者の部屋 :PHP Extension を作ろう第2回 - 引数と返値
– http://dsas.blog.klab.org/archives/50782987.html
● DSAS 開発者の部屋 :PHP Extension を作ろう第3回 - クラスを作ろう
– http://dsas.blog.klab.org/archives/50903613.html
Yohei Sato 32
参考書籍● Extending and Embedding PHP
– http://alturl.com/tu93
● PHP5 徹底攻略エクスパート編
– http://alturl.com/nymh