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
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
24
11k
LLMと連携したブログ書くエディタを作ってみた
mkazutaka
2
330
社内情報検索システムで用いられるRAGの4つの実装方法
mkazutaka
14
8.6k
ChatGPTを使ったSlackbotの実装いろいろ紹介
mkazutaka
2
2.5k
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
Amazon BedrockでサーバレスなAIお料理ボットを作成する!!
tosuri13
0
230
Perl 5 OOP機構30年史 - Perl 5's OOP Mechanism over the past 30 years
moznion
0
250
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
0
120
Google Sign-inの移行から始めるCredential Manager活用
clockvoid
0
310
unique パッケージから学ぶ interning と weak reference @ Asakusa.go#3
karamaru
2
810
今インフラ技術をイチから学び直すなら
yuhta28
1
140
How to Break into Reading Open Source
kaspth
2
210
Increased Performance and Developer Productivity with Jakarta EE 11
ivargrimstad
0
360
Shinjuku.rb#95:心の技術書紹介
free_world21
1
110
Kotlin 2.0 and Beyond
antonarhipov
2
150
Rubyとクリエイティブコーディングの輪の広がり / The Growing Circle of Ruby and Creative Coding
chobishiba
1
270
2024 컴포즈 정원사
jisungbin
0
150
Featured
See All Featured
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
326
21k
Fashionably flexible responsive web design (full day workshop)
malarkey
401
65k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
23
1.7k
Code Reviewing Like a Champion
maltzj
517
39k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
28
1.6k
Producing Creativity
orderedlist
PRO
340
39k
Practical Orchestrator
shlominoach
185
10k
How to Ace a Technical Interview
jacobian
274
23k
The Invisible Side of Design
smashingmag
295
50k
Building Adaptive Systems
keathley
36
2.1k
Rebuilding a faster, lazier Slack
samanthasiow
78
8.6k
The Language of Interfaces
destraynor
153
23k
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/