Contenu connexe Similaire à PHPの今とこれから2019 (20) Plus de Rui Hirokawa (14) PHPの今とこれから20196. 6
PHP 1 PHP 2 PHP 3 PHP 4 PHP 5 PHP 7
総ステップ数 2,946 40,377 141,066 406,227 1,103,84 1,127,75
0
200,000
400,000
600,000
800,000
1,000,000
1,200,000
総ステップ数
Python 3 Ruby 2
総ステップ数 422,087 863,913
0
200,000
400,000
600,000
800,000
1,000,000
1,200,000
総ステップ数
パーソナルツールからプラットフォームへ
大衆的ツール(Disりの対象)から安全で実用的な高性能ツールへ
1. 言語仕様:PHP 5.3/5.4で現代的なスクリプト言語に
2. 性能:PHP 5で高速化,PHP 7で最速に
3. セキュリティ:PHP 5でCoverity Scan適用
2015/122004/72000/51998/61997/111995/6
総ステップ数(.cファイル) 総ステップ数(.cファイル)
PHPの歩み
8. PHP アンケート 2018
PHPでよく使うバージョンは?
1) 使ったことがない
2) PHP 5.x
3) PHP 7.x
8
<?php
echo “Hello!”;
?>
10. PHPリリースサイクル
10
2017 2018 2019 2020 2021 2022 2023
5.6
7.0
7.1
7.2
7.3
7.4
アクティブサポート セキュリティ修正のみ
2019/12/1
PHPのライフサイクル:3年(バグ修正:2年、セキュリティ修正のみ:1年)
EOL以降はセキュリティ関連の修正も提供されず、非常に危険です
PHP5、PHP 7.0/7.1 は EOLとなっています
EOL 2018/12/31
https://wiki.php.net/rfc/releaseprocess
http://php.net/supported-versions.php
EOL 2018/12/3
EOL 2019/12/1
EOL 2020/11/30
EOL 2021/12/6
EOL 2022/11/28
11. PHPリリース情報
Release 5.6 7.0 7.1 7.2 7.3 変更
2018/12/6 5.6.39 7.0.33 7.3.0 PHP 7.3.0 Release, PHP 5.6/PHP 7.0 EOL
2019/1/10 5.6.40 7.1.26 7.2.14 7.3.1 CVE-2016-10166,2019-6977,9020,9021,9022,9023,9024 (buffer)
2019/2/7 7.2.15 7.3.2
2019/3/7 7.1.27 7.2.16 7.3.3 CVE-2019-9637,9638,9639,9640,9641 (uninitialized read)
2019/4/4 7.1.28 7.2.17 7.3.4 CVE-2019-11034,11035(heap overflow)
2019/5/2 7.1.29 7.2.18 7.3.5 CVE-2019-11036 (buffer overflow)
2019/5/30 7.1.30 7.2.19 7.3.6 CVE-2019-11038,11039,11040 (heap overflow)
2019/7/4 7.2.20 7.3.7
2019/8/1 7.1.31 7.2.21 7.3.8 CVE-2019-11041,11042 (heap overflow)
2019/8/29 7.1.32 7.2.22 7.3.9 CVE-2019-13224
2019/9/26 7.2.23 7.3.10
2019/10/24 7.1.33 7.2.24 7.3.11 CVE-2019-11043 (FPM,リモートコード実行)
2019/11/21 7.2.25 7.3.12
2019/11/28 PHP 7.4.0 Release
11
CVE-2019-11043: FPM (Nginx, Fast-CGI) リモートコード実行:
URL中の改行コード処理のバグ⇒PHP設定値の変更が可能 ⇒ 速やかな更新が必要
13. PHP7: より速く、快適に
Ryzen 5 2400G, Ubuntu 19.04
13
PHP 7.4は若干の改善
Zend/bench.php
Zend/microbench.php
0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
PHP
5.6
PHP
7.0
PHP
7.1
PHP
7.2
PHP
7.3
PHP
7.4
実行時間[s]
strcat(200000)
sieve(30)
nestedloop(12)
matrix(20)
heapsort(20000)
hash2(500)
hash1(50000)
fibo(30)
ary3(2000)
ary2(50000)
ary(50000)
ackermann(7)
mandel2
mandel
simpleudcall
simpleucall
simplecall
simple
0
1
2
3
4
5
6
7
8
PHP
5.6
PHP
7.0
PHP
7.1
PHP
7.2
PHP
7.3
PHP
7.4
$x = $f ? $f : tmp
$x = $f ? $f : $a
$x = $f ?: tmp
$x = $a ?: null
$x = $str[0]
$x = $hash['v']
$x = $GLOBALS['v']
$x = $_GET
$x = TEST
new Foo()
$x = Foo::TEST
$this->f()
empty($this->x)
isset($this->x)
$this->x--
$this->x++
--$this->x
++$this->x
$this->x += 2
$this->x = 0
$x = $this->x
Foo::f()
self::f()
empty(Foo::$x)
isset(Foo::$x)
Foo::$x = 0
$x = Foo::$x
empty(self::$x)
isset(self::$x)
self::$x = 0
$x = self::$x
int_func()
undef_func()
func()
empty_loop
14. PHP 7.4 改善/変更のポイント
14
<?php
class Foo {
public int $a;
public ?object $b = null;
}
$x = new Foo();
$x->a = “123”; // 文字列
var_dump($x->a); //
PHP 7.1で否決された案の見直し版
strict_types=1 (標準:無効)により型指定のチェックを厳密に指定できる
Nullable識別子(ヌルを代入可能):?
クラスプロパティの型指定
RFC: https://wiki.php.net/rfc/typed_properties_v2
int(123)
Fatal error: Uncaught TypeError: Typed property Foo::$a must be int, string used in test.php:8
<?php
declare(strict_types=1);
class Foo {
public int $a;
public ?object $b = null;
}
$x = new Foo();
$x->a = “123”; // エラー
var_dump($x->a);
15. PHP 7.4 改善/変更のポイント
15
opcache.preload=/var/www/preload.inc
OpCacheのプリロード指定: 起動時にキャッシュをロードすることで性能を改善
ZF2Testの応答速度50%改善
<?php
$path=”/var/www/lib”
if ($dh=opendir($path)) {
while (($file=readdir($dh))!==false) {
$fpath=$path.”/”.$file;
if (is_file($fpath) && preg_match(“/¥.php$/”,$fpath)) {
opcache_compile_file($fpath);
}
}
}
RFC: https://wiki.php.net/rfc/preload
preload.inc
16. PHP 7.4 改善/変更のポイント
16
FFI (Foreign Function Interface)により外部機能の利用が容易に
従来:エクステンション記述 ⇒ インターフェイス記述のみ
使い方
1. cdef(C言語の関数宣言, 共有ライブラリ)によりFFIオブジェクトを作成
2. 関数を使用
3. 外部変数の利用も可能
4. プリロードが可能: ffi.enable=preload + ffi.preload or opcache.preload
<?php
$ffi = FFI::cdef("double atan2(const double, const double);","libm.so.6");
var_dump($ffi->atan2(0.1,0.0));
RFC: https://wiki.php.net/rfc/ffi
float(1.5707963267949)
<?php
$a = FFI::new("unsigned char[1024*1024]");
for ($i = 0; $i < count($a); $i++) {
$a[$i] = $i;
}
var_dump($a[25]); int(25)
https://github.com/dstogov/php-tensorflow
17. PHP 7.4 改善/変更のポイント
17
RFC: https://wiki.php.net/rfc/spread_operator_for_array
配列スプレッド構文
array_merge()の代替:より高速でシンプル
ジェネレータ、(Traversableを実装する)オブジェクトもサポート
$a = [3,4];
$b = [1,2,...$a,5]; $b=[1,2,3,4,5]
function foo() { for ($i=1;$i<5;$i++){ yield $i;}}
$c = [...foo()]; $c=[1,2,3,4]
18. PHP 7.4 改善/変更のポイント
18
アロー関数(ショートクロージャ)
匿名関数の記述を簡略化
親スコープの変数を参照できる
注意:fn が予約語に
RFC: https://wiki.php.net/rfc/arrow_functions_v2
$y=1;
$a=[1,2,3];
$c = array_map(function ($x) use ($y) {
return ($x*$x+$y);
},$a));
function ($x) use ($y) {
return ($x*$x+$y);
}
fn($x)=>$x*$x+$y
$y=1;
$a=[1,2,3];
$c = array_map(fn($x)=>$x*$x+$y,$a));
匿名関数(クロージャ)
ショートクロージャ
19. PHP 7.4 改善/変更のポイント
19
??=構文
ある変数が設定されている場合⇒代入
そうでない場合に代替文字列を代入
$a['user'] = isset($a['user']) ? $a['user'] : 'nobody';
PHP 5
$a['user'] = $a['user'] ?? 'nobody';
$a['user'] ??= 'nobody'
PHP 7
PHP 7.4
NULL合体演算子
20. PHP 7.4 改善/変更のポイント
20
mb_str_split()関数追加: str_split()関数のマルチバイト対応版
数値リテラルセパレータ
+ .の優先順位が変更
$foo = 1000000;
RFC: https://wiki.php.net/rfc/numeric_literal_separator
$foo = 1_000_000;
print_r(mb_str_split(“日本語と英語", 2)); [0]=>日本,[1]=>語と, [2]=>英語
print_r(“3” . “5” + 7) ⇒ 35+7=42 “3”+12=“312”
PHP 7.3まで PHP 7.4
21. PHP 7.4 改善/変更のポイント
21
弱い参照 (Weak References)
オブジェクトの破棄に影響を及ぼさない参照
キャッシュのような構造の実装に有効
create()で作成、get()で取得
https://wiki.php.net/rfc/weakrefs
$obj=new stdClass;
debug_zval_dump($obj);
$ref = $obj; // シャローコピー
debug_zval_dump($obj);
debug_zval_dump($ref);
unset($obj); // コピー元削除
debug_zval_dump($ref);
object(stdclass)#1 refcount(2)
object(stdclass)#1 refcount(3)
object(stdclass)#1 refcount(2)
$obj=new stdClass;
debug_zval_dump($obj);
$ref = WeakReference::create($obj);
debug_zval_dump($obj);
debug_zval_dump($ref->get());
unset($obj); // コピー元削除
debug_zval_dump($ref->get());
object(stdclass)#1 refcount(2)
object(stdclass)#1 refcount(2)
NULL
object(stdclass)#1 refcount(3)
object(stdclass)#1 refcount(2)
変数コンテナ
$obj $ref
22. PHP 7.4 改善/変更のポイント
22
共変戻り値と反変パラメータに対応(警告がでなくなった)
https://wiki.php.net/rfc/covariant-returns-and-contravariant-parameters
class A {}
class C {
public function foo(A $foo) : C {}
}
class D extends C {
public function foo(A $foo) : D {}
}
Warning: Declaration of D::foo(A $foo):D should be
compatible with C::foo(A $foo):C
PHP 7.3まで
class A {}
class B extends A {}
class C {
public function foo(B $foo) {}
}
class D extends C {
public function foo(A $foo) {}
}
Warning: Declaration of D::foo(A $foo) should be co
mpatible with C::foo(B $foo)
PHP 7.3まで
23. PHP 7.4 改善/変更のポイント
23
オブジェクトのカスタムシリアライズの新しい機構: __serialize(), __unserialize()
Hash関数が常に有効に
廃止対象化(deprecate)、PHP 8で廃止
real型
波かっこによる配列オフセット指定: $c=[1,2,3]; $a=$c{1};
Magic quotes関連の関数
get_magic_quotes_gpc、get_magic_quotes_runtime関数、
FILTER_SANITIZE_MAGIC_QUOTES
allow_url_include パラメータ
24. PHPのこれから
PHP 8の開発が進んでいる
JIT (Just-in-Time Compiler)
24
https://wiki.php.net/rfc/jit
HHVMでJIT採用⇒PHP 5に比べて大幅高速化
PHP 7開発時にもJIT導入を検討(LLVM)⇒見送り(代わりにエンジン高速化)
LuaJITプロジェクト用に開発された軽量JITエンジンDynAsmを採用
現在はx86をサポート、将来的にはARM等もサポート
OPCacheを拡張して実装:オペコードの代わりにネーティブコードをキャッシュ
SSA解析
DynAsmコンパイル
キャッシュ
実行
SSA: 静的単一代入
25. PHP8 JIT: より速く、快適に
Ryzen 5 2400G, Ubuntu 19.04
25
PHP 8では実行速度が大幅改善
実用アプリではそれほどでもない
Zend/bench.php
Zend/microbench.php
0
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0.4
0.45
0.5
PHP 7.4 PHP 7.4
cache
PHP 8.0
cache
PHP 8.0 jit
strcat(200000)
sieve(30)
nestedloop(12)
matrix(20)
heapsort(20000)
hash2(500)
hash1(50000)
fibo(30)
ary3(2000)
ary2(50000)
ary(50000)
ackermann(7)
mandel2
mandel
simpleudcall
simpleucall
simplecall
simple
0
0.5
1
1.5
2
2.5
PHP 7.4 PHP 7.4
cache
PHP 8.0
cache
PHP 8.0 jit
$x = $f ? $f : tmp
$x = $f ? $f : $a
$x = $f ?: tmp
$x = $a ?: null
$x = $str[0]
$x = $hash['v']
$x = $GLOBALS['v']
$x = $_GET
$x = TEST
new Foo()
$x = Foo::TEST
$this->f()
empty($this->x)
isset($this->x)
$this->x--
$this->x++
--$this->x
++$this->x
$this->x += 2
$this->x = 0
$x = $this->x
Foo::f()
self::f()
empty(Foo::$x)
isset(Foo::$x)
Foo::$x = 0
$x = Foo::$x
empty(self::$x)
isset(self::$x)
self::$x = 0
$x = self::$x
int_func()
undef_func()
func()
empty_loop
26. PHPのこれから
JITにすれば単純に早くなるというわけでもない⇒opcache.jitオプションで調整
JITコンパイルに時間がかかる⇒LuaJIT採用で解消
プロファイルで頻繁に使用される部分を抽出し、JITを適用
最適化を同時に行うことが重要
CPUアーキテクチャに合わせた最適化、SIMD命令の使用
26
opcache.jit=1205
CPU固有の最適化(C) 0:オフ、1: AVX命令生成を有効化
レジスタ配置(R)
0:なし、1:ローカル線形スキャン、2: グローバル線形スキャン
JITトリガ(T)
0:スクリプトロード時、1:初回実行時、
2:初回時プロファイル、2回目にコンパイル
3:プロファイルでホットな関数を見つけてコンパイル
4:docコメントで@jitタグが指定された関数をコンパイル
最適化レベル(O)
0:JIT無効、1:JIT最小実行、2:インライン化
3:関数毎の静的型推論による最適化
4:静的型推論とコールツリーによる最適化
5:静的型推論と内部処理解析による最適化
27. 0
0.2
0.4
0.6
0.8
1
1.2
1.4
1.6
1.8
PHP 8.0
jit
205 1235 1201 1005
$x = $f ? $f : tmp
$x = $f ? $f : $a
$x = $f ?: tmp
$x = $a ?: null
$x = $str[0]
$x = $hash['v']
$x = $GLOBALS['v']
$x = $_GET
$x = TEST
new Foo()
$x = Foo::TEST
$this->f()
empty($this->x)
isset($this->x)
$this->x--
$this->x++
--$this->x
++$this->x
$this->x += 2
$this->x = 0
$x = $this->x
Foo::f()
self::f()
empty(Foo::$x)
isset(Foo::$x)
Foo::$x = 0
0
0.05
0.1
0.15
0.2
0.25
0.3
PHP 8.0
jit
205 1235 1201 1005
strcat(200000)
sieve(30)
nestedloop(12)
matrix(20)
heapsort(20000)
hash2(500)
hash1(50000)
fibo(30)
ary3(2000)
ary2(50000)
ary(50000)
ackermann(7)
mandel2
mandel
simpleudcall
simpleucall
simplecall
simple
PHP8 JIT: より速く、快適に
Ryzen 5 2400G, Ubuntu 19.04
27
opcache.jit=CRTO (デフォルト:1205) のどれが効いているか?
最適化(O)>AVX(C)>レジスタ配置(R)の順に効果が大きい
バッファサイズも影響する
Zend/bench.php
Zend/microbench.php
AVX
オフ
Hot
解析
最適化
なし
レジスタ
配置なし
最適化
なし
AVX
オフ
Hot
解析
レジスタ
配置なし
28. PHPの成功と未来
1. 学習が容易: 言語がシンプル、ドキュメントが豊富
2. 進化を継続: Webの進化に対応し、必要十分な解を提供
PHPは歯ブラシのようなもの。いつも使う役に立つシンプルな
ツールだけど、誰も歯ブラシのことなんて気にしないよね。
PHPは「問題を解くためのシンプルなツール」なのさ。
(http://en.wikiquote.org/wiki/Rasmus_Lerdorf)
Rasmus語録
30. 30
PHP Conference 2019 の見どころ
1F大展示 2F小展示 Track 3 (コンベ鶯) Track 4(コンベ梅) Track 5(AB会) Track 6 (特別会)
コミュニティアップデート PHPにおける並列処理と
非同期処理入門
Chatworkのシステムか
ら学ぶレガシーなPHPの
限界とレガシーからの脱
却
MVCにおけるモデルと
は何か
PHP初心者セッション Hash,Cryptgraphy,
and PHP
Laravel x クリーンアーキ
テクチャ
徳丸先生による徳丸試
験例題解説
思想と理想の果てに –
クリーンアーキテクチャの
Webフレームワークを作
ろう
PHP開発環境で使う
Kubernetes
「弁護士ドットコム」を作り
続ける開発組織について
「グランブルーファンタ
ジー」開発エンジニア
の考え方
PHPerのためのテスト
コード入門
Putting Legacy to
REST with
middileware
20年前のMySQL、今の
MySQL
改善失敗から学ぶ、レガ
シープロダクトに立ち向
かうチーム作り
新しい概念のWAFが
叶える、クラウドネイ
ティブ時代のセキュリ
ティ
Composerって何?どう
動くの?読んでみました!
PHPUnit: Past,
Present and Future
Webサービスのトラブル
の現場
プログラム未経験から
たった3か月で圧倒的な
開発力を身につける
知見のない技術スタッ
クをプロダクション導入
するエンジニアの導入
戦略
PHPは何を捨て、どんな
力を手に入れてきたの
か?
5か月でカバレッジを
20%から90%にした話
脆弱性から学ぶWebセ
キュリティ
PHPからgoへの移行
で分かったこと
Zend VMにおける例外
の実装
「CPUとは何か」をPHP
で考える
オニギリペイのセキュリティ
事故に学ぶ安全なサービ
スの構築法
REST 6+4の制約 このPHP QAツールがす
ごい!2019
15年続くWebサービ
スへのCI/CDとテスト
コードの導入
PHPを学ぶということ How to Supercharge
your PHP Web API
ApacheからLiteSpeed
に乗り換えてみません
か?
LT
11:00
12:10
13:00
13:35
14:10
14:45
15:20
16:30
17:40
15:55
11:35
31. 31
PHP カンファレンス 2019 が PHPer の皆様にとってチャレンジ、成長、
そしてその先へと向かう原動力となることを、
そしてこれから先の 10 年、20 年、25 年と、
Web の発展とともに PHP の発展と日本 PHP ユーザ会として
PHPer が切磋琢磨しな がらより良い未来を PHP とともに作り上げることを願っています。