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
DRFを少しずつ オニオンアーキテクチャに寄せていく DjangoCongress JP 2025
nealle
2
300
PromptyによるAI開発入門
ymd65536
1
120
Generating OpenAPI schema from serializers throughout the Rails stack - Kyobashi.rb #5
envek
1
450
Djangoにおける複数ユーザー種別認証の設計アプローチ@DjangoCongress JP 2025
delhi09
PRO
4
520
Visual StudioのGitHub Copilotでいろいろやってみる
tomokusaba
1
230
Expoによるアプリ開発の現在地とReact Server Componentsが切り開く未来
yukukotani
2
290
やっと腹落ち「スプリント毎に動くモノをリリースする」〜ゼロから始めるメガバンクグループのアジャイル実践〜
sasakendayo
0
240
Webフレームワークとともに利用するWeb components / JSConf.jp おかわり
spring_raining
1
150
Modern Angular with Signals and Signal StoreNew Rules for Your Architecture @bastacon 2025 in Frankfurt
manfredsteyer
PRO
0
150
CIBMTR振り返り+敗北から学ぶコンペの取り組み方反省
takanao
1
230
The Price of Micro Frontends… and Your Alternatives @bastacon 2025 in Frankfurt
manfredsteyer
PRO
0
290
CDKを使ったPagerDuty連携インフラのテンプレート化
shibuya_shogo
0
130
Featured
See All Featured
Done Done
chrislema
182
16k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2.1k
The Illustrated Children's Guide to Kubernetes
chrisshort
48
49k
Fashionably flexible responsive web design (full day workshop)
malarkey
406
66k
Practical Orchestrator
shlominoach
186
10k
Build The Right Thing And Hit Your Dates
maggiecrowley
34
2.6k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
30
4.6k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
46
2.4k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
59k
Large-scale JavaScript Application Architecture
addyosmani
511
110k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.7k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.3k
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/