-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCleanUpExec.php
More file actions
62 lines (57 loc) · 1.63 KB
/
CleanUpExec.php
File metadata and controls
62 lines (57 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* ファイルクリーンアップ ライブラリ
*
* @author Mitsuru Mutaguchi <mutaguchi@opensource-workshop.jp>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
* @copyright Copyright 2014, NetCommons Project
*/
/**
* ファイルクリーンアップ ライブラリ
*
* @author Mitsuru Mutaguchi <mutaguchi@opensource-workshop.jp>
* @package NetCommons\CleanUp\Lib
* @see MailSend よりコピー
*/
class CleanUpExec {
/**
* ファイルクリーンアップ呼び出し
*
* @param array $data received post data. ['CleanUp']['plugin_key'][] = 'announcements'
* @return void
*/
public static function cleanUp($data) {
$plugins = implode(' ', $data['CleanUp']['plugin_key']);
// バックグラウンドでファイルクリーンアップ
// コマンド例) Console/cake clean_up.clean_up clean_up announcements blogs
self::execInBackground(APP . 'Console' . DS . 'cake clean_up.clean_up clean_up ' . $plugins);
}
/**
* バックグラウンド実行
*
* @param string $cmd コマンド
* @return void
*/
public static function execInBackground($cmd) {
if (self::isWindows()) {
// Windowsの場合
pclose(popen('cd ' . APP . ' && start /B ' . $cmd, 'r'));
} else {
// Linuxの場合
// logrotate問題対応 http://dqn.sakusakutto.jp/2012/08/php_exec_nohup_background.html
exec('nohup ' . $cmd . ' > /dev/null &');
}
}
/**
* 動作しているOS がWindows かどうかを返す。
*
* @return bool
*/
public static function isWindows() {
if (DIRECTORY_SEPARATOR == '\\') {
return true;
}
return false;
}
}