-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run
74 lines (62 loc) · 1.87 KB
/
run
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
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env php
<?php
/**
* 入口文件
*
* @author mybsdc <[email protected]>
* @date 2019/3/2
* @time 11:05
* @link https://github.com/luolongfei/freenom
*/
error_reporting(E_ERROR);
ini_set('display_errors', 1);
set_time_limit(0);
define('IS_CLI', PHP_SAPI === 'cli');
define('DS', DIRECTORY_SEPARATOR);
define('ROOT_PATH', realpath(__DIR__));
define('VENDOR_PATH', realpath(ROOT_PATH . '/vendor'));
define('APP_PATH', realpath(ROOT_PATH . '/app'));
define('RESOURCES_PATH', realpath(ROOT_PATH . '/resources'));
date_default_timezone_set('Asia/Shanghai');
/**
* 注册错误处理
*/
register_shutdown_function('customize_error_handler');
/**
* 注册异常处理
*/
set_exception_handler('exception_handler');
require VENDOR_PATH . '/autoload.php';
use Luolongfei\Lib\Log;
use Luolongfei\Lib\Mail;
use Luolongfei\Lib\TelegramBot;
/**
* @throws Exception
*/
function customize_error_handler()
{
if (!is_null($error = error_get_last())) {
Log::error('程序意外终止', $error);
// Mail::send('主人,程序意外终止', '具体情况我也不清楚,请查看服务器日志定位问题。');
// TelegramBot::send('主人,程序意外终止,具体情况我也不清楚,请查看服务器日志定位问题。');
}
}
/**
* @param \Exception $e
*
* @throws \Exception
*/
function exception_handler($e)
{
Log::error('未捕获的异常:' . $e->getMessage());
Mail::send('主人,未捕获的异常', "具体的异常内容是:\n" . $e->getMessage());
TelegramBot::send('主人,发现未捕获的异常:' . $e->getMessage());
}
try {
system_check();
$class = sprintf('Luolongfei\App\Console\%s', get_argv('c', 'FreeNom'));
$fn = get_argv('m', 'handle');
$class::instance()->$fn();
} catch (\Exception $e) {
system_log(sprintf('执行出错:<red>%s</red>', $e->getMessage()), $e->getTrace());
}