fix && style

This commit is contained in:
小新
2021-01-19 09:59:09 +08:00
parent 48d5278907
commit 2170b22806
3 changed files with 48 additions and 37 deletions
@@ -1,13 +1,14 @@
<?php <?php
use Workerman\Worker; use Workerman\Worker;
use Workerman\Lib\Timer; use Workerman\Lib\Timer;
// worker // worker
$webDirSource = dirname(dirname(dirname(__FILE__))); $webDirSource = dirname(dirname(dirname(__FILE__)));
$worker = new Worker(); $worker = new Worker();
$worker->name = 'FileMonitor'; $worker->name = 'FileMonitor';
$worker->reloadable = false; $worker->reloadable = false;
$worker->onWorkerStart = function() $worker->onWorkerStart = function () {
{
global $webDirSource; global $webDirSource;
Timer::add(300, 'check_files_remove', $webDirSource); Timer::add(300, 'check_files_remove', $webDirSource);
}; };
@@ -16,6 +17,7 @@ $worker->onWorkerStart = function()
function check_files_remove($webDirSource) function check_files_remove($webDirSource)
{ {
try {
$pdo = new PDO('sqlite:' . $webDirSource . '/sql'); $pdo = new PDO('sqlite:' . $webDirSource . '/sql');
$data = $pdo->query("select * from file_info where addtime < '" . (time() - 60 * 60 * 2 + 5) . "'")->fetchAll(); $data = $pdo->query("select * from file_info where addtime < '" . (time() - 60 * 60 * 2 + 5) . "'")->fetchAll();
foreach ($data as $item) { foreach ($data as $item) {
@@ -25,5 +27,13 @@ function check_files_remove($webDirSource)
$pdo->exec("delete from file_info where id=" . $item['id']); $pdo->exec("delete from file_info where id=" . $item['id']);
} }
$pdo = null; $pdo = null;
} catch (\Throwable $e) {
print_r([
'message' => $e->getMessage(),
'code' => $e->getCode(),
'line' => $e->getLine(),
'trace' => $e->getTraceAsString(),
]);
}
return; return;
} }
@@ -66,7 +66,12 @@ class Events
}; };
$task_connection->connect(); $task_connection->connect();
} catch (\Throwable $e) { } catch (\Throwable $e) {
print_r([
'message' => $e->getMessage(),
'code' => $e->getCode(),
'line' => $e->getLine(),
'trace' => $e->getTraceAsString(),
]);
} }
} }
@@ -22,8 +22,6 @@ $task_worker->onMessage = function ($connection, $task_data) use ($webDir,$datat
$connection->send("true"); $connection->send("true");
$pdo = null; $pdo = null;
return true; return true;
break;
case "2": case "2":
$pdo = new PDO('sqlite:' . dirname(dirname(dirname(__FILE__))) . '/sql'); $pdo = new PDO('sqlite:' . dirname(dirname(dirname(__FILE__))) . '/sql');
$data = $pdo->query("select down_num from statistics where id=1")->fetch(); $data = $pdo->query("select down_num from statistics where id=1")->fetch();
@@ -39,7 +37,6 @@ $task_worker->onMessage = function ($connection, $task_data) use ($webDir,$datat
$pdo = null; $pdo = null;
$connection->send("true"); $connection->send("true");
return true; return true;
break;
} }
} }
if (preg_match("/%|\"|\.\.|\\\|\?|\||`|&|reboot|rm |mv |shutdown|<|>|sh |;|'/", $dataArr['url']) if (preg_match("/%|\"|\.\.|\\\|\?|\||`|&|reboot|rm |mv |shutdown|<|>|sh |;|'/", $dataArr['url'])
@@ -130,7 +127,6 @@ $task_worker->onMessage = function ($connection, $task_data) use ($webDir,$datat
} }
}; };
if (!defined('GLOBAL_START')) { if (!defined('GLOBAL_START')) {
Worker::runAll(); Worker::runAll();