diff --git a/GatewayWorker/Applications/autoReload/start.php b/GatewayWorker/Applications/autoReload/start.php index 0ce928e..07a1f9d 100644 --- a/GatewayWorker/Applications/autoReload/start.php +++ b/GatewayWorker/Applications/autoReload/start.php @@ -1,13 +1,14 @@ name = 'FileMonitor'; $worker->reloadable = false; -$worker->onWorkerStart = function() -{ +$worker->onWorkerStart = function () { global $webDirSource; Timer::add(300, 'check_files_remove', $webDirSource); }; @@ -16,14 +17,23 @@ $worker->onWorkerStart = function() function check_files_remove($webDirSource) { - $pdo = new PDO('sqlite:' . $webDirSource . '/sql'); - $data = $pdo->query("select * from file_info where addtime < '".(time() - 60*60*2+5)."'")->fetchAll(); - foreach($data as $item){ - if(is_file($item['path'])){ - unlink($item['path']); + try { + $pdo = new PDO('sqlite:' . $webDirSource . '/sql'); + $data = $pdo->query("select * from file_info where addtime < '" . (time() - 60 * 60 * 2 + 5) . "'")->fetchAll(); + foreach ($data as $item) { + if (is_file($item['path'])) { + unlink($item['path']); + } + $pdo->exec("delete from file_info where id=" . $item['id']); } - $pdo->exec("delete from file_info where id=".$item['id']); + $pdo = null; + } catch (\Throwable $e) { + print_r([ + 'message' => $e->getMessage(), + 'code' => $e->getCode(), + 'line' => $e->getLine(), + 'trace' => $e->getTraceAsString(), + ]); } - $pdo = null; return; -} \ No newline at end of file +} diff --git a/GatewayWorker/Applications/githubT/Events.php b/GatewayWorker/Applications/githubT/Events.php index 0bf2ae4..f906395 100644 --- a/GatewayWorker/Applications/githubT/Events.php +++ b/GatewayWorker/Applications/githubT/Events.php @@ -38,7 +38,7 @@ class Events */ public static function onConnect($client_id) { - // 向当前client_id发送数据 + // 向当前client_id发送数据 // Gateway::sendToClient($client_id, "Hello $client_id\r\n"); // 向所有人发送 // Gateway::sendToAll("$client_id login\r\n"); @@ -58,15 +58,20 @@ class Events }; $task_connection->onMessage = function ($task_connection, $data) use ($client_id) { - if($data == "true") { + if ($data == "true") { $task_connection->close(); - }else{ + } else { $data && Gateway::sendToClient($client_id, $data . "\r\n"); } }; $task_connection->connect(); } catch (\Throwable $e) { - + print_r([ + 'message' => $e->getMessage(), + 'code' => $e->getCode(), + 'line' => $e->getLine(), + 'trace' => $e->getTraceAsString(), + ]); } } diff --git a/GatewayWorker/Applications/githubT/start_sync.php b/GatewayWorker/Applications/githubT/start_sync.php index 9543ba1..2816d1e 100644 --- a/GatewayWorker/Applications/githubT/start_sync.php +++ b/GatewayWorker/Applications/githubT/start_sync.php @@ -7,45 +7,42 @@ $task_worker = new Worker('text://127.0.0.1:16345'); $task_worker->count = 10; $task_worker->name = 'TaskWorker_github'; $datatime = date("Ymd"); -$webDir = dirname(dirname(dirname(dirname(__FILE__)))) . "/staticweb/source/".$datatime; +$webDir = dirname(dirname(dirname(dirname(__FILE__)))) . "/staticweb/source/" . $datatime; -$task_worker->onMessage = function ($connection, $task_data) use ($webDir,$datatime) { +$task_worker->onMessage = function ($connection, $task_data) use ($webDir, $datatime) { $dataArr = json_decode($task_data, true); - if(!$dataArr){ + if (!$dataArr) { return; } - if(isset($dataArr['type'])){ - switch($dataArr['type']){ + if (isset($dataArr['type'])) { + switch ($dataArr['type']) { case "1": $pdo = new PDO('sqlite:' . dirname(dirname(dirname(__FILE__))) . '/sql'); $pdo->exec("UPDATE statistics SET down_num=down_num+1 where id=1"); $connection->send("true"); $pdo = null; return true; - break; - case "2": $pdo = new PDO('sqlite:' . dirname(dirname(dirname(__FILE__))) . '/sql'); $data = $pdo->query("select down_num from statistics where id=1")->fetch(); $down_num = $data[0]; $connection->send(json_encode([ - 'status' => 0, - 'msg' =>"完成", - 'data' =>[ - 'sta' => 4, - 'down_num' => $down_num - ] - ],JSON_UNESCAPED_UNICODE) . "\r\n"); + 'status' => 0, + 'msg' => "完成", + 'data' => [ + 'sta' => 4, + 'down_num' => $down_num + ] + ], JSON_UNESCAPED_UNICODE) . "\r\n"); $pdo = null; $connection->send("true"); return true; - break; } } - if (preg_match("/%|\"|\.\.|\\\|\?|\||`|&|reboot|rm |mv |shutdown|<|>|sh |;|'/",$dataArr['url']) + if (preg_match("/%|\"|\.\.|\\\|\?|\||`|&|reboot|rm |mv |shutdown|<|>|sh |;|'/", $dataArr['url']) || ( - !preg_match("/^((https|http):\/\/)?([\w\.\s\S\/\-\_^]+?)\.(tar\.gz|gz|tgz|tar\.bz2|bz2|msi|tar|zip|tar\.xz|tar\.z|rpm|deb|exe|apk|dmg|7z|rar)$/iu",$dataArr['url'],$ext) + !preg_match("/^((https|http):\/\/)?([\w\.\s\S\/\-\_^]+?)\.(tar\.gz|gz|tgz|tar\.bz2|bz2|msi|tar|zip|tar\.xz|tar\.z|rpm|deb|exe|apk|dmg|7z|rar)$/iu", $dataArr['url'], $ext) && !preg_match("/^https:\/\/github.com\/([\w\/\-\.\_]+)$/iu", $dataArr['url'] ) ) @@ -57,7 +54,7 @@ $task_worker->onMessage = function ($connection, $task_data) use ($webDir,$datat if (!is_dir($webDir)) { mkdir($webDir, 0777); } - if(stristr($dataArr['url'],'github') && (!isset($ext) || !$ext)) { + if (stristr($dataArr['url'], 'github') && (!isset($ext) || !$ext)) { //github的检出、打包 $connection->send(json_encode([ 'status' => 0, @@ -68,7 +65,7 @@ $task_worker->onMessage = function ($connection, $task_data) use ($webDir,$datat ], JSON_UNESCAPED_UNICODE) . "\r\n"); $git_dir_path = md5($dataArr['url']); if (!is_dir($webDir . "/" . $git_dir_path) && !is_file($webDir . "/{$git_dir_path}.tar")) { - system('cd ' . $webDir . ';git clone --depth=50 "' . $dataArr['url'] . '" ' . $git_dir_path); + system('cd ' . $webDir . ';git clone --depth=50 "' . $dataArr['url'] . '" ' . $git_dir_path); } $connection->send(json_encode([ 'status' => 0, @@ -78,7 +75,7 @@ $task_worker->onMessage = function ($connection, $task_data) use ($webDir,$datat ] ], JSON_UNESCAPED_UNICODE) . "\r\n"); if (!is_file($webDir . "/{$git_dir_path}.tar")) { - if(!is_dir($webDir."/".$git_dir_path)){ + if (!is_dir($webDir . "/" . $git_dir_path)) { $connection->send(json_encode([ 'status' => 1, 'msg' => "您输入的链接可能是不支持的后缀,如果是git仓储,请确认链接正确", @@ -102,7 +99,7 @@ $task_worker->onMessage = function ($connection, $task_data) use ($webDir,$datat ] ], JSON_UNESCAPED_UNICODE) . "\r\n"); $connection->send("true"); - }else{ + } else { //普通的压缩包下载处理 $connection->send(json_encode([ 'status' => 0, @@ -113,7 +110,7 @@ $task_worker->onMessage = function ($connection, $task_data) use ($webDir,$datat ], JSON_UNESCAPED_UNICODE) . "\r\n"); $fileExt = end($ext); $fileName = md5($dataArr['url']) . ".{$fileExt}"; - system('cd ' . $webDir . '; wget "'.$dataArr['url'] . '" -O '.$fileName); + system('cd ' . $webDir . '; wget "' . $dataArr['url'] . '" -O ' . $fileName); $pdo = new PDO('sqlite:' . dirname(dirname(dirname(__FILE__))) . '/sql'); $pdo->exec("insert into file_info ('path', 'addtime') VALUES ('" . $webDir . "/{$fileName}" . "','" . time() . "')"); $pdo = null; @@ -130,7 +127,6 @@ $task_worker->onMessage = function ($connection, $task_data) use ($webDir,$datat } - }; if (!defined('GLOBAL_START')) { Worker::runAll();