Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
20181215 php-srcで遊ぶよ
Search
Matsumoto Kazutaka
December 15, 2018
Programming
2
1.1k
20181215 php-srcで遊ぶよ
php-srcで遊んでみた
php conference 2018の資料です
Matsumoto Kazutaka
December 15, 2018
Tweet
Share
More Decks by Matsumoto Kazutaka
See All by Matsumoto Kazutaka
GPTsより精度の高いRAGシステムの構築
mkazutaka
26
12k
LLMと連携したブログ書くエディタを作ってみた
mkazutaka
2
390
社内情報検索システムで用いられるRAGの4つの実装方法
mkazutaka
14
9k
ChatGPTを使ったSlackbotの実装いろいろ紹介
mkazutaka
2
2.6k
Development of Mercari's web in 2019
mkazutaka
0
1k
メルカリ Backendエンジニアの日常 ~Backend Engineer Drink Meetup #1~
mkazutaka
0
2k
Other Decks in Programming
See All in Programming
1年目の私に伝えたい!テストコードを怖がらなくなるためのヒント/Tips for not being afraid of test code
push_gawa
1
640
Boost Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
1k
AWS Step Functions は CDK で書こう!
konokenj
4
810
CSS Linter による Baseline サポートの仕組み
ryo_manba
1
160
Ça bouge du côté des animations CSS !
goetter
2
160
pylint custom ruleで始めるレビュー自動化
shogoujiie
0
160
はじめての Go * WASM * OCR
sgash708
1
120
Boos Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
560
ABEMA iOS 大規模プロジェクトにおける段階的な技術刷新 / ABEMA iOS Technology Upgrade
akkyie
1
230
お前もAI鬼にならないか?👹Bolt & Cursor & Supabase & Vercelで人間をやめるぞ、ジョジョー!👺
taishiyade
7
4.2k
なぜイベント駆動が必要なのか - CQRS/ESで解く複雑系システムの課題 -
j5ik2o
14
4.8k
Rubyと自由とAIと
yotii23
6
1.9k
Featured
See All Featured
Art, The Web, and Tiny UX
lynnandtonic
298
20k
Scaling GitHub
holman
459
140k
Being A Developer After 40
akosma
89
590k
Typedesign – Prime Four
hannesfritz
41
2.5k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
49
2.3k
How to Ace a Technical Interview
jacobian
276
23k
Making the Leap to Tech Lead
cromwellryan
133
9.1k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
13
1k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
193
16k
Optimising Largest Contentful Paint
csswizardry
34
3.1k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
4
380
GraphQLとの向き合い方2022年版
quramy
44
14k
Transcript
php-src で遊ぶよ Github:@mkazutaka Twitter:@makazutaka Name: Kazutaka Matsumoto
who am i? 名前: Kazutaka Matsumoto 所属: 株式会社メルカリ 職種: バックエンドエンジニア(PHP
or Go) PHP 歴: 8 ヶ月(2018 新卒)
最近書いたよー Microservices にジョインするには知らない技術が多すぎたので 一通り触ってみた話 https://tech.mercari.com/entry/2018/12/02/160455
タイトル php-src で遊ぶよ
PHP 初心者のジレンマ PHP で開発するからにはphp-src のことを知りたい php-src を知らなくてもPHP はかける ex) Laravel
を読むのにphp-src は必要ない
ジレンマの難しいところ php-src は自分の時間で読む必要がある
さらにphp-src を読むハードルの高さも相まる
さらに プログラミング言語読んでも ・お金も儲からないし ・仕事に直接役立つわけでもないし ・そもそも効果わからんし
php-src で遊ぼうというタイトルで 申し込みしました
反省
今回のスライド pros) 浅いところまでなので聞き手が理解できる cons) 知識が浅い
Goal this section php-src で遊ぶ 副産物: php-src について知れる
Question php-src の中身を見たことある人 どれくらいいますか?
Question 拡張ライブラリを書いたことある人 どれくらいいます?
はじまり
はじめになにをやるか
手元にソースコードを置く
手元にソースコードを置く $ git clone
[email protected]
:php/php-src.git $ cd php-src $ git
checkout -b develop
ビルドする
Docke le $ vim Dockerfile // Dockerfile FROM ubuntu:18.10 RUN
apt update RUN apt upgrade -y RUN apt install -y build-essential autoconf automake \ libtool bison re2c libxml2-dev libsqlite3-dev ENV DIST_DIR=/tmp/php-src RUN mkdir -p $DIST_DIR WORKDIR $DIST_DIR
docker build And php-src build php-src のビルド ## docker run
-v $PWD:/tmp/php-src -it php-src ./buildconf でも可能 > ./buildconf > ./configure --enable-debug --enable-maintainer-zts \ --with-readline \ --disable-all > grep "cpu cores" /proc/cpuinfo #4 > make -j4 $ docker build . -t php-src $ docker run -v $PWD:/tmp/php-src -it php-src bash root@# ls CODING_STANDARDS Makefile.fragments README.NEW-OUTPUT-API README.W CONTRIBUTING.md Makefile.gcov README.PARAMETER_PARSING_API README.i ...
実行 root@# sapi/cli/php -m [PHP Modules] Core ... [Zend Modules]
root@# sapi/cli/php -a Interactive mode enabled php > echo 'Hello World'; Hello World
PHP overview ref: https://entwickler.de/wp-content/uploads/2013/06/wpm_2013_06.pdf
PHP overview overview ref: https://www.slideshare.net/do_aki/php-sapi-zendengine3
SAPI The Server Application Programming Interface PHP にアクセスするためのインターフェース エンドポイントとしての役割を持つ CLI
やCGI はSAPI を経由してPHPCore 等にアクセス
ZendEngine コンパイラやVM といった機能を提供 上記を実現するための機能を提供 ZendEngine はPHP Core やSAPI から独立して提供されているはず メモリ管理のために構造体などを提供
詳しくは@do_aki さんのPHP と SAPI と ZendEngine3 がおすすめ http://d.hatena.ne.jp/do_aki/20180313/1520937886
PHP Core ZendEngine と役割は似てる ネットワークの管理やコマンドラインからのarugment の読むこむ 関数としてはfopen_function 等がある
php-src の主なせディレクトリ構成 . ├── Zend // ZendEngine 本体のディレクトリ ├── ext
// 拡張ライブラリや動的ライブラリが格納 ├── main // SAPI やextension の共通メソッドが置かれている ...
拡張モジュール作ってみる 拡張モジュールの雛形は、ext_skel コマンドで作成できる $ ./ext_skel.php --ext 'hello_world'; cd hello_world $
ls config.m4 config.w32 hello_world.c php_hello_world.h tests $ ./buildconf $ ./configure --enable-debug \ --enable-maintainer-zts \ --with-readline \ --enable-hello_world --disable-all $ make -j4 $ sapi/cli/php -m [PHP Modules] ... hello_world ...
書いてみる 関数の定義 // ext/hello_world/hello_world.c PHP_FUNCTION(say_hello_world) { ZEND_PARSE_PARAMETERS_NONE(); php_printf("Hello World"); }
引数の定義 // ext/hello_world/hello_world.c ZEND_BEGIN_ARG_INFO(arginfo_say_hello_world, 0) ZEND_END_ARG_INFO() module functions に追加 //
ext/hello_world/hello_world.c static const zend_function_entry hello_world_functions[] = { PHP_FE(say_hello_world, arginfo_say_hello_world) PHP_FE_END };
実行してみる ## ビルドし直す $ ./configure --enable-debug \ --enable-maintainer-zts \ --with-readline
\ --enable-hello_world --disable-all $ make -j4 $ grep "cpu cores" /proc/cpuinfo #4 $ sapi/cli/php -a php > say_hello_world(); Hello World
関数に引数を使う PHP_FUNCTION(say_with_world) { char *s; size_t s_len; zend_string *r; ZEND_PARSE_PARAMETERS_START(1,
1) Z_PARAM_STRING(s, s_len) ZEND_PARSE_PARAMETERS_END(); r = strpprintf(0, "%s world", s); RETURN_STR(r); } ZEND_BEGIN_ARG_INFO(arginfo_say_with_world, 0) ZEND_ARG_INFO(0, str) ZEND_END_ARG_INFO()
static const zend_function_entry hello_world_functions[] = { ... PHP_FE(say_with_world, arginfo_say_with_world) ...
}; 実行 php > print_r(say_with_world('hoge')); hoge world
まとめ php-src で遊んでみました それに伴い、PHP Core とZend Engine に対して簡単に解説をした また実際に、拡張ライブラリを実装を紹介した
時間があれば
RFC(Request for Comments) 技術仕様の提案や決定が書かれているページがある https://wiki.php.net/rfc Github のPR のリンクが書かれている
RFC: array_key_ rst().... 読める気がする RFC: https://wiki.php.net/rfc/array_key_ rst_last PR: https://github.com/php/php-src/pull/3256
まとめ php-src で遊ぶ php-src の概要を知る必要がある ソースコードの読み方を知る必要がある
終わり
参考資料 https://wiki.php.net/rfc http://php.net/manual/ja/internals2.ze1.zendapi.php https://qiita.com/7968/items/2aa487e2e515dba2fd03 https://thinkit.co.jp/free/article/0705/7/1/