Last active
October 4, 2016 04:13
-
-
Save Huruikagi/0f9d39eeaadecc33907d409795e871c6 to your computer and use it in GitHub Desktop.
WordPressプラグイン有効化時にNode.jsでサーバーを起動する ref: http://qiita.com/Huruikagi/items/37f3885e415b9371a2db
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* | |
| * Plugin Name: WPChat | |
| * Description: WordPressのユーザー情報を利用してチャットができるようにするプラグインです。 | |
| * Version: 0.1; | |
| * Author: Huruikagi | |
| * Author URI: https://github.com/Huruikagi | |
| */ | |
| // プラグインが有効になった際の処理 | |
| function on_activate() { | |
| // Node.jsでチャット用のサーバーを起動する処理 | |
| // エントリポイントのパス | |
| $path = join(DIRECTORY_SEPARATOR, array(__DIR__, 'chat-server', 'express', 'app.js')); | |
| if (PHP_OS === 'WIN32' || PHP_OS === 'WINNT') { | |
| // windowsのとき | |
| $command = "node $path > nul 2>&1"; | |
| $fp= popen("start /B cmd /c $command", "r"); | |
| pclose($fp); | |
| } else { | |
| // unix系の時 | |
| $command = "node $path"; | |
| exec("$command >/dev/null 2>&1 &"); | |
| } | |
| } | |
| register_activation_hook(__FILE__, 'on_activate'); | |
| // プラグインが無効になったときの処理 | |
| function on_deactivate() { | |
| // サーバー停止リクエストを投げる | |
| // TODO URLを設定情報から読み出す | |
| file_get_contents("http://localhost:8888/kill"); | |
| } | |
| register_deactivation_hook(__FILE__, 'on_deactivate'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment