More Related Content Similar to 先取り!PHP 7 と WordPress (20) More from Masashi Shinbara (20) 先取り!PHP 7 と WordPress2. (c) 2015 Masashi Shinbara @shin1x1
Shin x blog
http://www.1x1.jp/blog/
2006年から WordPress
いつもお世話になってます!
5. PHP 7
(c) 2015 Masashi Shinbara @shin1x1
• PHP の次期メジャーバージョン
(現在は、PHP 5)
• PHP 6 は、永久欠番
• 2015/11 頃にリリース予定(現在は、β2)
8. ?? 演算子
(c) 2015 Masashi Shinbara @shin1x1
• 連想配列にキーが無ければ、右辺を返す
• キーが存在しなくても、Notice が出ない
$array = ['name' => 'Jun'];
echo $array['name'] ?? 'default';
=> Jun
echo $array['nothing'] ?? 'default';
=> default
=> Noticeエラーにならない!
9. スカラタイプヒンティング
(c) 2015 Masashi Shinbara @shin1x1
• int / float / string がタイプヒンティングに
• 型が合わなければ、自動変換 or TypeError
class Foo
{
public function say(int $i, float $f, string $s)
{
}
}
$foo = new Foo;
$foo->say(1, 1.0, '1');
10. 戻り値タイプヒンティング
(c) 2015 Masashi Shinbara @shin1x1
• クラス、インターフェース名、スカラ型
callable、self、parent、Closure
class Bar
{
public function get_int(): int
{
return 1;
}
}
11. 匿名クラス
(c) 2015 Masashi Shinbara @shin1x1
•new class で匿名クラスを作成
$object = new class {
public function say()
{
echo 'Hello' . PHP_EOL;
}
};
$object->say(); // Hello
12. 匿名クラス
(c) 2015 Masashi Shinbara @shin1x1
• 基底クラスを継承したり、
インターフェースやトレイトを追加できる
$object = new class implements Readable
{
use ReaderTrait;
};
$object->read();
13. クロージャの即時実行
(c) 2015 Masashi Shinbara @shin1x1
• JavaScript の IIFE ライクな記法
• クロージャや匿名クラスを即時実行
(function ($message) {
echo $message . PHP_EOL;
})('Hello');
14. 廃止された機能
(c) 2015 Masashi Shinbara @shin1x1
• <% や <%= 記法(<?= は有効)
• switch 文の 多重 default
• mysql 関数(PECL 拡張あり)
• ereg 関数
• split 関数
• =& new 記法
WordPressの移行なら、こちらが重要!
16. WordPress on PHP 7
(c) 2015 Masashi Shinbara @shin1x1
MySQL
PHP 7.0β2
nginx
WordPress
17. (c) 2015 Masashi Shinbara @shin1x1
WordPress on PHP 7
素の WordPress 4.2
PHP 7 上で動作する
18. Shin x blog on PHP 7
(c) 2015 Masashi Shinbara @shin1x1
9 年熟成した WordPress
プラグイン多数
テーマカスタマイズ
実働しているWordPressを PHP 7に設置
19. Shin x blog on PHP 7
(c) 2015 Masashi Shinbara @shin1x1
プラグインやテーマが原因で
動かない。。。
エラーメッセージを見ながら
1つづづ修正していく。
動いた!
20. 修正した箇所
(c) 2015 Masashi Shinbara @shin1x1
PHP Parse error: syntax error, unexpected
'new' (T_NEW)
[修正] =& new Hoge -> = new hoge
PHP Fatal error: Uncaught Error: Call to undefined
function split()
[修正] split() -> explode()
21. WordPress on PHP 7
(c) 2015 Masashi Shinbara @shin1x1
• WordPress 本体は対応済 ?
• プラグインやテーマは対応が必要な場合も
• エラーメッセージを足がかりに修正
=> WP-DEBUG を true に
=> 開発、検証環境で行う!
23. 検証環境
(c) 2015 Masashi Shinbara @shin1x1
MySQL
PHP 5.6
MySQL
PHP 7.0β2
nginx
WordPress 4.2
nginx
WordPress 4.2
24. WordPress 4.2
(c) 2015 Masashi Shinbara @shin1x1
0
8.5
17
25.5
34
5.6 7.0β2
RPS
インストール直後の状態
1秒あたりの処理リクエスト数
7.0β2 の方が 2.4 倍多い
ab -c 30 -n 1000 で計測
25. Shin x blog
(c) 2015 Masashi Shinbara @shin1x1
0
7.5
15
22.5
30
5.6 7.0β2
RPS
テーマカスタム、プラグイン多数
1秒あたりの処理リクエスト数
7.0β2 の方が 4.5 倍多い
ab -c 30 -n 1000 で計測
26. メモリ使用量
(c) 2015 Masashi Shinbara @shin1x1
0
1,250
2,500
3,750
5,000
5.6 7.0β2
kilobyte
Shin x blog のピークメモリ
メモリ使用量が 56 %減少
(約半分に!)
memory_get_peak_usage(true) で計測
28. まとめ
(c) 2015 Masashi Shinbara @shin1x1
• PHP 7 が、11月リリース予定
• 分かりやすい特徴は、パフォーマンスアップ
• WordPress 本体は動いている
(プラグイン、テーマは確認を!)