LoginSignup
0
0

More than 3 years have passed since last update.

phpメソッドをすげ替える掟破りの技、runkit

Posted at

概要

  • phpのrunkitを使うと掟破りのアレコレができる
  • strtotime()を叩いた時に-9h分勝手にやるとか

使いどころ

  • 弊社ブラウザゲームでは開発環境で未来日のデバッグをする時などに。

参考ドキュメント

実行例

// 時間調整
//date()をオーバーライドしてsimulationTimeを返す
runkit_function_copy('date', 'date2');
runkit_function_redefine('date', '$a, $b=null', 'return date2($a, $b ? $b : strtotime("' . $simulationTime . '"));');

//strtotime()をオーバーライドしてsimulationTimeを返す
runkit_function_copy('strtotime', 'strtotime2');
runkit_function_redefine('strtotime', '$a, $b=null', 'return strtotime2($a, $b ? $b : strtotime2(date2("Y-m-d H:i:s", time())));');

//time()をオーバーライドしてsimulationTimeを返す
runkit_function_redefine('time', '', 'return strtotime2("' . $simulationTime . '");');

//DBの時刻も上書きする
Db::Update("set TIMESTAMP = unix_timestamp('{$simulationTime}');");

ハマリどころ

オーバーライドが使えない

strtotime() is an internal function and runkit.internal_override is disabled in file /xxxx/xxx.php
  • 普通に「runkit.internal_override使えねーよ」って言われた

解決方法

phpinfoを見てみる

Directive   Local Value Master Value
runkit.internal_override    Off Off
runkit.superglobal  no value    no value

iniファイルで設定できる

phpinfo.additional .ini files parsedにパスがある

/etc/php.d/runkit.ini

runkit.internal_override On

雑感

  • 非常に強力なので知らない人には意識させない(FWの上位で利用するetc)のが大事
  • ただ開発環境のデバッグなどでイベントやキャンペーンを開きたい時に、本番相当の開催データのままデプロイできるのは非常に有用
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0