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
300
社内情報検索システムで用いられるRAGの4つの実装方法
mkazutaka
14
8.4k
ChatGPTを使ったSlackbotの実装いろいろ紹介
mkazutaka
2
2.5k
Development of Mercari's web in 2019
mkazutaka
0
1k
メルカリ Backendエンジニアの日常 ~Backend Engineer Drink Meetup #1~
mkazutaka
0
1.9k
Other Decks in Programming
See All in Programming
ピグパーティにおけるMongoDB CommunityバージョンからAtlasへの移行事例
10969hotaka
0
130
AWS CDKにおける「再利用性」を考える / aws-cdk-reusability
gotok365
6
1.3k
データカタログ運用物語 〜令和6年夏の理想と現実〜
kuro_kurorrr
0
110
DMMプラットフォームにおけるTiDBの導入から運用まで
pospome
7
3k
Jetpack for KMP
fornewid
1
290
Xcode 16のPreviewModifierと@Previewableを活用した効率的なプレビュー方法の考察
ojun9
2
160
入社1ヶ月でここまでやった!Findy Toolsインフラ支援の最適化
rvirus0817
6
1.4k
Cloudflare Workers x AWS Lambdaの組み合わせユースケース / Cloudflare Workers x AWS Lambda Combination Use Case
seike460
PRO
2
310
Clean Architecture by TypeScript & NestJS
ryounasso
0
150
[After Kotlin Fest 2024 LT Night @ Sansan] もっともっとKotlinを好きになる!K2 Compiler Pluginで遊んでみよう!
kitakkun
2
260
Microservices rules (July 2024) : what good looks like
cer
PRO
0
1.6k
SRE チーム立ち上げ前に考えたこと・取り組んだこと / Considerations and Preparations Before Establishing an SRE Team
mackey0225
3
320
Featured
See All Featured
From Idea to $5000 a Month in 5 Months
shpigford
377
46k
Docker and Python
trallard
37
2.9k
Adopting Sorbet at Scale
ufuk
71
8.8k
Happy Clients
brianwarren
94
6.6k
Robots, Beer and Maslow
schacon
PRO
157
8.1k
Building Flexible Design Systems
yeseniaperezcruz
323
37k
Learning to Love Humans: Emotional Interface Design
aarron
269
39k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
36
9.1k
Building Better People: How to give real-time feedback that sticks.
wjessup
357
18k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
16
1.6k
What the flash - Photography Introduction
edds
65
11k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
29
2.5k
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/