More Related Content What's hot (20)
PPTX
async/await のしくみ
信之 岩永
PPTX
Writing php extensions in golang
do_aki
Viewers also liked (20)
PDF
Internal php and gdb php core
alpha86
PDF
Create your own PHP extension, step by step - phpDay 2012 Verona
Patrick Allaert
PPTX
Techtalk2015 MOD_PHP vs PHP-FPM
Webscale
PPT
Međuinduktivitet i zračni transformatori (slike)
IrmaKajd
PPT
Бренд-комьюнити от Sitko.Ru (Brand-Community of Sitko.Ru)
Serj Nazarov
PDF
Gianni Marconato - Costruire conoscenza professionale in rete attraverso la n...
KnowCamp
PDF
Privacy-Aware Data Management in Information Networks - SIGMOD 2011 Tutorial
Kun Liu
PPTX
Duurzame asfaltontwikkelingen | Jan Voskuilen (InfraTech 2015)
CROW
Similar to php and sapi and zendengine2 and... (16)
PDF
YAPC::Asia 2014 - 半端なPHPDisでPHPerに陰で笑われないためのPerl Monger向け最新PHP事情
Junichi Ishida
PDF
"More" Introduction to Zend Tool
sasezaki
More from do_aki (20) PPTX
Tritonn から Elasticsearch への移行話
do_aki
PPTX
signal の話 或いは Zend Signals とは何か
do_aki
PPTX
N対1 レプリケーション + Optimizer Hint
do_aki
PPTX
20150212 プレゼンテーションzen
do_aki
PPTX
MySQL Casual Talks 7 「N:1 レプリケーション ~進捗どうですか?~」
do_aki
PPTX
20141017 introduce razor
do_aki
PPTX
20141011 mastering mysqlnd
do_aki
PPTX
PHP から Groonga を使うにはこんなコードになるよ!
do_aki
PPTX
N:1 Replication meets MHA
do_aki
PPTX
セキュアそうでセキュアじゃない少しセキュアな気分になれるmysql_config_editor
do_aki
PPTX
マスタN対スレーブ1レプリケーションの作り方 ~あれから~
do_aki
PPTX
Excel is image viewer
do_aki
PDF
A bridge between php and ruby
do_aki
PDF
Ruby and comparison_and...php
do_aki
Recently uploaded (9) PDF
SIG-AUDIO 2025 Vol.02 オンラインセミナー 「GDC2025 オーディオ報告会」SIG-Audio_GDC2025_報告会資料_渡辺さ...
IGDA Japan SIG-Audio
PDF
SIG-AUDIO 2025 Vol.02 オンラインセミナー 「GDC2025 オーディオ報告会」SIG-Audio_GDC2024_報告会資料_増野さ...
IGDA Japan SIG-Audio
PDF
マルチAIエージェントの産業界での実践に向けたオープンソース活動の展望 - Japan Regional User Group (RUG) Meet-Up
Kosaku Kimura
PDF
論文紹介:AutoPrompt: Eliciting Knowledge from Language Models with Automatically ...
Toru Tamaki
PDF
論文紹介:Unbiasing through Textual Descriptions: Mitigating Representation Bias i...
Toru Tamaki
php and sapi and zendengine2 and...
7. php のコアって
Those who know don't talk.
(知ってる人は教えようとしない)
Those who talk don't know.
(教えてる人はあまり知らない)
PHP: Zend API: PHP のコアをハックする より
http://www.php.net/manual/ja/internals2.ze1.zendapi.php
11. SAPI module
• Web サーバ/OS
と PHP の橋渡
し
• エントリーポ
イントはここ
にある
• 21種類の
bundle module
PHP Script
Extensions
SAPI
module
Zend
Engine2
12. PHP SAPIs
aolserver / apache / apache2filter /
apache2handler / apache_hooks /
caudium / cgi / cli / continuity / embed
/ fpm / isapi / litespeed / milter / nsapi /
phttpd / pi3web / roxen / thttpd / tux /
webjames
(under sapi directory in php-5.5.8 source code)
14. ZendEngine2
• Parser / Compiler
• VirtualMachine
• Memory
Manager
• Garbage
Collection
• (TSRM)
etc…
PHP Script
Extensions
SAPI
module
Zend
Engine2
15. PHP(Zend) Extension
• Core
• Bundle
Extensions
• PECL
Extensions
• PHP Ext と
Zend Ext の違
いはよくわか
らない
PHP Script
Extensions
SAPI
module
Zend
Engine2
PHP extensionとZend extensionの違い - hnwの日記 http://d.hatena.ne.jp/hnw/20130715
17. PHP Script
• <?php
• OpCode に変換
され、VM で実
行
• Extension や
SAPI module を
介して外部と
の入出力が行
われる
PHP Script
Extensions
SAPI
module
Zend
Engine2
19. life of php process
TSRM startup (only ZTS)
SAPI startup
PHP module startup (Zend startup)
PHP request startup
execute php script
PHP request shutdown
PHP module shutdown
SAPI shutdown
TSRM shutdown
20. startup process in SAPI
• prepare sapi_module (sapi_module_struct)
• TSRM startup
– TSRM:=Thread Safe Resource Manager
• SAPI startup
– SAPI:= Server API
– SG (sapi_globals_struct@main/SAPI.h)
• call php_module_startup
– main/main.c
21. php_module_startup
• call zend_startup
• init some global vars (EG,PG,SG,GC_G)
• init some constant
– PHP_VERSION,PHP_OS,PHP_SAPI etc...
• register auto globals ($_GET, $_POST …)
• read and scan ini files
• init php (zend) extensions
22. zend_startup
• init GLOBAL TABLE
– FUNCTION/CLASS/AUTO_GLOBALS/CONSTANTS
• init INI_SCNG / LANG_SCNG
• init interned strings
• register builtin_functions
– strlen, func_get_arg, class_exists, create_function
etc... (Zend/zend_builtin_functions.c)
• register standard constants
– E_ERROR, TRUE, FALSE, NULL etc...
• register $GLOBALS
23. request process (apache)
• prepare SG(request_info)
• call php_request_startup
– reset gc / compile/ executer
– init output buffering stack
– sapi_activate
– init PG(http_globals)
• execute php script
27. 最後に
• php 処理系の全体像を解説しました
• プロセスの持ち方や、startup/shutdown の
制御は SAPI によって異なります
• SAPI と ZendEngine2 の責任の境界がイマ
イチ分からない (SG や sapi_module の扱
い)
• 間違ってたら指摘ください