diff --git a/apps/config/httpd.php b/apps/config/httpd.php index 29f81b1..4284ace 100644 --- a/apps/config/httpd.php +++ b/apps/config/httpd.php @@ -67,15 +67,15 @@ // 开启协程 'enable_coroutine' => false, // 连接处理线程数 - 'reactor_num' => 8, + 'reactor_num' => 1, // 工作进程数 - 'worker_num' => 8, + 'worker_num' => 20, // PID 文件 'pid_file' => '/var/run/rid-httpd.pid', // 日志文件路径 'log_file' => '/tmp/rid-httpd.log', // 进程的最大任务数 - 'max_request' => 10000, + 'max_request' => 3000, // 退出等待时间 'max_wait_time' => 60, // 异步安全重启 diff --git a/apps/controllers/TrackerController.php b/apps/controllers/TrackerController.php index df3e480..11a7d67 100644 --- a/apps/controllers/TrackerController.php +++ b/apps/controllers/TrackerController.php @@ -9,7 +9,7 @@ namespace apps\controllers; use Rid\Utils\IpUtils; -use SandFoxMe\Bencode\Bencode; +use Rid\Bencode\Bencode; use apps\models\User; use apps\exceptions\TrackerException; diff --git a/apps/models/Torrent.php b/apps/models/Torrent.php index 30c4093..92f8ff3 100644 --- a/apps/models/Torrent.php +++ b/apps/models/Torrent.php @@ -8,8 +8,7 @@ namespace apps\models; -use SandFoxMe\Bencode\Bencode; - +use Rid\Bencode\Bencode; use Rid\Exceptions\NotFoundException; class Torrent diff --git a/apps/models/form/TorrentUploadForm.php b/apps/models/form/TorrentUploadForm.php index 4b1d945..9c3dc03 100644 --- a/apps/models/form/TorrentUploadForm.php +++ b/apps/models/form/TorrentUploadForm.php @@ -11,9 +11,8 @@ use apps\models\Torrent; use Rid\Validators\Validator; - -use SandFoxMe\Bencode\Bencode; -use SandFoxMe\Bencode\Exceptions\ParseErrorException; +use Rid\Bencode\Bencode; +use Rid\Bencode\ParseErrorException; use Symfony\Component\Validator\Constraints as Assert; use Symfony\Component\Validator\Context\ExecutionContextInterface; diff --git a/composer.json b/composer.json index b71bb85..43ba1b5 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,6 @@ "ext-swoole": "*", "ext-mbstring": "*", "ext-simplexml": "*", - "sandfoxme/bencode": "^1.2", "robthree/twofactorauth": "^1.6", "swiftmailer/swiftmailer": "^6.1", "twig/twig": "^2.0", diff --git a/framework/Bencode/Bencode.php b/framework/Bencode/Bencode.php new file mode 100644 index 0000000..d99cbf3 --- /dev/null +++ b/framework/Bencode/Bencode.php @@ -0,0 +1,145 @@ + $value) { + if ($key !== ++$check) { + $list = false; + break; + } + } + if ($list) { + $return .= 'l'; + foreach ($data as $value) { + $return .= self::encode($value); + } + } else { + $return .= 'd'; + foreach ($data as $key => $value) { + $return .= self::encode(strval($key)); + $return .= self::encode($value); + } + } + $return .= 'e'; + } elseif (is_integer($data)) { + $return = 'i' . $data . 'e'; + } else { + $return = strlen($data) . ':' . $data; + } + return $return; + } + + /** + * Given a path to a file, decode the contents of it + * + * @param string $path + * @return mixed + * @throws ParseErrorException + */ + public static function load(string $path) + { + return self::decode(file_get_contents($path, FILE_BINARY)); + } + + /** + * Given a path for a file, encode the contents of it + * + * @param string $path + * @param $data + * @return mixed + */ + public static function dump(string $path, $data) + { + return file_put_contents($path, self::encode($data)); + } +} diff --git a/framework/Bencode/ParseErrorException.php b/framework/Bencode/ParseErrorException.php new file mode 100644 index 0000000..d9d70c2 --- /dev/null +++ b/framework/Bencode/ParseErrorException.php @@ -0,0 +1,14 @@ +