服务器列表优化速度

This commit is contained in:
wanyongkang
2020-11-27 10:46:39 +08:00
parent 8306c61f33
commit d4aca75a4a
8 changed files with 305 additions and 203 deletions

View File

@@ -139,7 +139,7 @@ class Fastphp
global $is_script;
$formal_origin = $this->config['formal_origin']; //跨域访问的时候才会存在此字段
$origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '';
if (!in_array($origin, $formal_origin) && !$is_script) {
if ((!in_array($origin, $formal_origin) && !$is_script) || $_SERVER['LOGNAME'] == 'wyk') {
define('DB_HOST', $this->config['db']['host']);
define('DB_PORT', $this->config['db']['port']);
define('DB_NAME', $this->config['db']['dbname']);

View File

@@ -1,7 +1,7 @@
<?php
$is_script = 1;
include __DIR__ . '/../index.php';
include_once __DIR__ . '/../index.php';
use app\api\model\Product;
$product_model = new Product;

View File

@@ -1,7 +1,7 @@
<?php
$is_script = 1;
include __DIR__ . '/../index.php';
include_once __DIR__ . '/../index.php';
use app\manager\model\FollowRecord;
use app\manager\model\ProductOrder;

View File

@@ -5,10 +5,10 @@
* @Author: kangkang
* @Date: 2020-10-03 18:23:43
* @LastEditors: Please set LastEditors
* @LastEditTime: 2020-11-26 11:36:17
* @LastEditTime: 2020-11-27 09:43:59
*/
$is_script = 1;
include __DIR__ . '/../index.php';
include_once __DIR__ . '/../index.php';
use app\api\model\Finance as FinanceModel;
use app\api\model\ProductOrder as ProductOrderModel;

View File

@@ -4,11 +4,11 @@
* @version:
* @Author: kangkang
* @Date: 2020-10-03 18:23:43
* @LastEditors: kangkang
* @LastEditTime: 2020-10-28 10:29:17
* @LastEditors: Please set LastEditors
* @LastEditTime: 2020-11-27 09:44:13
*/
$is_script = 1;
include __DIR__ . '/../index.php';
include_once __DIR__ . '/../index.php';
use app\api\model\IncomeCheck as IncomeCheckModel;
use app\api\model\ProductOrder as ProductOrderModel;

View File

@@ -0,0 +1,270 @@
<?php
function auto_format_list(){
$product_list = [0, 1, 2, 4, 5, 6, 8, 10, 13, 14, 15, 16];
foreach ($product_list as $product) {
switch ($product) {
case 0:
format_all_product(__DIR__ . '/data/all.csv');
break;
case 8:
format_xingxing(__DIR__ . '/data/xingxing.csv', __DIR__ . '/data/2288.csv', 'xxip.vip');
break;
case 6:
format_product(__DIR__ . '/data/xianfeng.csv', 'xfip.vip');
break;
case 13:
format_product(__DIR__ . '/data/jike.csv', 'jkip.com');
break;
case 1:
format_product(__DIR__ . '/data/qiangzi.csv', 'qzip.vip');
break;
case 2:
format_product(__DIR__ . '/data/xunlian.csv', 'xlip.vip');
break;
case 14:
format_product(__DIR__ . '/data/tiantian.csv', 'ttip.cn');
break;
case 5:
format_product(__DIR__ . '/data/laoying.csv', 'lyip.vip');
break;
case 4:
format_product(__DIR__ . '/data/jinrui.csv', 'jrip.vip');
break;
case 10:
format_product(__DIR__ . '/data/wuxian.csv', 'wxip.net');
break;
case 16:
format_product(__DIR__ . '/data/shihui.csv', 'shihui');
break;
case 15:
format_product(__DIR__ . '/data/gongxiang.csv', 'shihui');
break;
}
}
}
function format_all_product($file_path)
{
$list = [];
$dns = '';
$record = [];
$citys = [];
$user_count = 0;
$count = 0;
$file = fopen($file_path, 'r');
$file1 = fopen(__DIR__ . '/data/download/all.csv', 'w');
while ($info = fgetcsv($file)) {
$data['name'] = $info[0];
switch ($data['name']) {
case '星星':
$dns = 'xxip.vip';
break;
case '先锋':
$dns = 'xfip.vip';
break;
case '极客':
$dns = 'jkip.com';
break;
case '强子':
$dns = 'qzip.vip';
break;
case '讯连':
$dns = 'xlip.vip';
break;
case '天天':
$dns = 'ttip.cn';
break;
case '老鹰':
$dns = 'lyip.vip';
break;
case '金瑞':
$dns = 'jrip.vip';
break;
case '无限':
$dns = 'wxip.net';
break;
case '实惠':
$dns = 'shihui';
break;
case '共享':
$dns = 'shihui';
break;
}
$city = city_exist($citys, $info[1]);
$citys[] = $city;
$data['city'] = $city;
$data['supply'] = $info[2] ?? '';
$data['ip'] = $info[3] ?? '';
$data['daikuan'] = $info[4] ?? '';
$data['onlineuser'] = $info[5] ?? '';
$data['maxuser'] = $info[6] ?? '';
$data['online'] = $info[7] ?? '';
$data['status'] = $info[8] ?? '';
if ($dns != 'shihui') {
$ip = explode('.', ($info[9] ?? ''));
$data['nasname'] = $ip[0] ? ip_repeat($record, $ip[0], $dns) . '.' . $dns : '';
} else {
$data['nasname'] = $info[9] ?? '';
}
fputcsv($file1, $data);
}
fclose($file);
fclose($file1);
}
function format_product($file_path, $dns = '')
{
$list1 = [];
$list = [];
$user_count = 0;
$count = 0;
$key = '';
$citys = [];
$file = fopen($file_path, 'r');
$file_path1 = explode('/', $file_path);
$file1 = fopen(__DIR__ . '/data/download/' . $file_path1[8], 'w');
$record = [];
while ($info = fgetcsv($file)) {
if (in_array($info['1'], ['曾', '龙'])) {
continue;
}
if (empty($info[9])) {
$key = $info[1];
}
$data['name'] = $info[0];
$city = city_exist($citys, $info[1]);
$citys[] = $city;
$data['city'] = $city;
$data['supply'] = $info[2] ?? '';
$data['ip'] = $info[3] ?? '';
$data['daikuan'] = $info[4] ?? '';
$data['onlineuser'] = $info[5] ?? '';
$data['maxuser'] = $info[6] ?? '';
$data['online'] = $info[7] ?? '';
$data['status'] = $info[8] ?? '';
if ($dns != 'shihui') {
$ip = explode('.', ($info[9] ?? ''));
$data['nasname'] = $ip[0] ? ip_repeat($record, $ip[0]) . '.' . $dns : '';
} else {
$data['nasname'] = $info[9] ?? '';
}
$list1[$key][] = $data;
}
foreach ($list1 as $k => $val) {
foreach ($val as $net_data) {
fputcsv($file1, $net_data);
}
}
fclose($file1);
fclose($file);
}
function format_xingxing($file_path1, $file_path2, $dns)
{
$list1 = [];
$list = [];
$user_count = 0;
$count = 0;
$key = '';
$citys = [];
$file1 = fopen($file_path1, 'r');
$file2 = fopen($file_path2, 'r');
$record = [];
$keys = [];
$file_path = explode('/', $file_path1);
$file3 = fopen(__DIR__ . '/data/download/' . $file_path[8], 'w');
while ($info = fgetcsv($file1)) {
if (empty($info[9])) {
$key = $info[1];
$keys[] = $key;
}
$data['name'] = $info[0];
$city = city_exist($citys, $info[1]);
$citys[] = $city;
$data['city'] = $city;
$data['supply'] = $info[2] ?? '';
$data['ip'] = $info[3] ?? '';
$data['daikuan'] = $info[4] ?? '';
$data['onlineuser'] = $info[5] ?? '';
$data['maxuser'] = $info[6] ?? '';
$data['online'] = $info[7] ?? '';
if (!empty($info[9])) {
$user_count += $data['online'] == '正常' ? 1 : 0;
$count++;
}
$data['status'] = $info[8] ?? '';
$ip = explode('.', ($info[9] ?? ''));
$data['nasname'] = $ip[0] ? ip_repeat($record, $ip[0]) . '.' . $dns : '';
$list1[$key][] = $data;
}
while ($info = fgetcsv($file2)) {
if (empty($info[9])) {
$key = $info[1];
if (in_array($key, $keys)) {
continue;
}
}
$data['name'] = $info[0];
$city = city_exist($citys, $info[1]);
$citys[] = $city;
$data['city'] = $city;
$data['supply'] = $info[2] ?? '';
$data['ip'] = $info[3] ?? '';
$data['daikuan'] = $info[4] ?? '';
$data['onlineuser'] = $info[5] ?? '';
$data['maxuser'] = $info[6] ?? '';
$data['online'] = $info[7] ?? '';
$data['status'] = $info[8] ?? '';
$ip = explode('.', ($info[9] ?? ''));
$data['nasname'] = $ip[0] ? ip_repeat($record, $ip[0]) . '.' . $dns : '';
$list1[$key][] = $data;
}
foreach ($list1 as $k => $val) {
foreach ($val as $net_data) {
fputcsv($file3, $net_data);
}
}
fclose($file1);
fclose($file2);
fclose($file3);
}
function ip_repeat(&$record, $ip, $dns = '')
{
for ($i = 2; $i < 100; $i++) {
if (in_array($ip . $dns, $record)) {
if (in_array($ip . $dns . 'v' . $i, $record)) {
continue;
} else {
$record[] = $ip . $dns . 'v' . $i;
return $ip . 'v' . $i;
}
} else {
$record[] = $ip . $dns;
return $ip;
}
}
}
function city_exist($citys, $city)
{
for ($i = 2; $i < 100; $i++) {
if (in_array($city, $citys)) {
if (in_array($city . $i, $citys)) {
continue;
} else {
return $city . $i;
}
} else {
return $city;
}
}
}

View File

@@ -5,7 +5,7 @@
* @Author: kangkang
* @Date: 2020-11-06 14:32:57
* @LastEditors: Please set LastEditors
* @LastEditTime: 2020-11-25 19:50:43
* @LastEditTime: 2020-11-27 10:32:41
*/
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: *");
@@ -14,92 +14,53 @@ header("Access-Control-Allow-Credentials: true");
$id = $_GET['product'];
switch ($id) {
case 0:
format_all_product(__DIR__ . '/data/all.csv');
get_all_product(__DIR__ . '/data/download/all.csv');
break;
case 8:
format_xingxing(__DIR__ . '/data/xingxing.csv', __DIR__ . '/data/2288.csv', 'xxip.vip');
get_product(__DIR__ . '/data/download/xingxing.csv');
break;
case 6:
format_product(__DIR__ . '/data/xianfeng.csv', 'xfip.vip');
get_product(__DIR__ . '/data/download/xianfeng.csv');
break;
case 13:
format_product(__DIR__ . '/data/jike.csv', 'jkip.com');
get_product(__DIR__ . '/data/download/jike.csv');
break;
case 1:
format_product(__DIR__ . '/data/qiangzi.csv', 'qzip.vip');
get_product(__DIR__ . '/data/download/qiangzi.csv');
break;
case 2:
format_product(__DIR__ . '/data/xunlian.csv', 'xlip.vip');
get_product(__DIR__ . '/data/download/xunlian.csv');
break;
case 14:
format_product(__DIR__ . '/data/tiantian.csv', 'ttip.cn');
get_product(__DIR__ . '/data/download/tiantian.csv');
break;
case 5:
format_product(__DIR__ . '/data/laoying.csv', 'lyip.vip');
get_product(__DIR__ . '/data/download/laoying.csv');
break;
case 4:
format_product(__DIR__ . '/data/jinrui.csv', 'jrip.vip');
get_product(__DIR__ . '/data/download/jinrui.csv');
break;
case 10:
format_product(__DIR__ . '/data/wuxian.csv', 'wxip.net');
get_product(__DIR__ . '/data/download/wuxian.csv');
break;
case 16:
format_product(__DIR__ . '/data/shihui.csv', 'shihui');
get_product(__DIR__ . '/data/download/shihui.csv');
break;
case 15:
format_product(__DIR__ . '/data/gongxiang.csv', 'shihui');
get_product(__DIR__ . '/data/download/gongxiang.csv');
break;
}
function format_all_product($file_path)
function get_all_product($file_path)
{
$list = [];
$dns = '';
$record = [];
$citys = [];
$user_count = 0;
$count = 0;
$file = fopen($file_path, 'r');
$file1 = fopen(__DIR__ . '/data/download/all.csv', 'w');
while ($info = fgetcsv($file)) {
$data['name'] = $info[0];
switch ($data['name']) {
case '星星':
$dns = 'xxip.vip';
break;
case '先锋':
$dns = 'xfip.vip';
break;
case '极客':
$dns = 'jkip.com';
break;
case '强子':
$dns = 'qzip.vip';
break;
case '讯连':
$dns = 'xlip.vip';
break;
case '天天':
$dns = 'ttip.cn';
break;
case '老鹰':
$dns = 'lyip.vip';
break;
case '金瑞':
$dns = 'jrip.vip';
break;
case '无限':
$dns = 'wxip.net';
break;
case '实惠':
$dns = 'shihui';
break;
case '共享':
$dns = 'shihui';
break;
}
$city = city_exist($citys,$info[1]);
$citys[] = $city;
$city = $info[1];
$data['city'] = $city;
$data['supply'] = $info[2]??'';
$data['ip'] = $info[3]??'';
@@ -107,36 +68,26 @@ function format_all_product($file_path)
$data['onlineuser'] = $info[5]??'';
$data['maxuser'] = $info[6]??'';
$data['online'] = $info[7]??'';
$data['status'] = $info[8] ?? '';
if (!empty($info[9])) {
$user_count += $data['online'] == '正常' ? 1 : 0;
$count++;
}
$data['status'] = $info[8]??'';
if ($dns != 'shihui') {
$ip = explode('.', ($info[9]??''));
$data['nasname'] = $ip[0] ? ip_repeat($record, $ip[0],$dns) . '.' . $dns : '';
} else {
$data['nasname'] = $info[9]??'';
}
fputcsv($file1, $data);
$data['nasname'] = $info[9]??'';
$list[] = $data;
}
fclose($file);
fclose($file1);
echo json_encode(['data' => $list, 'count' => $count, 'use_count' => $user_count]);
}
function format_product($file_path, $dns = '')
function get_product($file_path, $dns = '')
{
$list1 = [];
$list = [];
$user_count = 0;
$count = 0;
$key = '';
$citys = [];
$file = fopen($file_path, 'r');
$file_path1 = explode('/', $file_path);
$file1 = fopen(__DIR__ . '/data/download/' . $file_path1[8], 'w');
$record = [];
while ($info = fgetcsv($file)) {
if (in_array($info['1'], ['曾', '龙'])) {
@@ -146,8 +97,7 @@ function format_product($file_path, $dns = '')
$key = $info[1];
}
$data['name'] = $info[0];
$city = city_exist($citys,$info[1]);
$citys[] = $city;
$city = $info[1];
$data['city'] = $city;
$data['supply'] = $info[2]??'';
$data['ip'] = $info[3]??'';
@@ -155,142 +105,20 @@ function format_product($file_path, $dns = '')
$data['onlineuser'] = $info[5]??'';
$data['maxuser'] = $info[6]??'';
$data['online'] = $info[7]??'';
$data['status'] = $info[8] ?? '';
if (!empty($info[9])) {
$user_count += $data['online'] == '正常' ? 1 : 0;
$count++;
}
$data['status'] = $info[8]??'';
if ($dns != 'shihui') {
$ip = explode('.', ($info[9]??''));
$data['nasname'] = $ip[0] ? ip_repeat($record, $ip[0]) . '.' . $dns : '';
} else {
$data['nasname'] = $info[9]??'';
}
$data['nasname'] = $info[9]??'';
$list1[$key][] = $data;
}
foreach ($list1 as $k => $val) {
foreach ($val as $net_data) {
fputcsv($file1, $net_data);
$list[] = $net_data;
}
}
fclose($file1);
fclose($file);
echo json_encode(['data' => $list, 'count' => $count, 'use_count' => $user_count]);
}
function format_xingxing($file_path1, $file_path2, $dns)
{
$list1 = [];
$list = [];
$user_count = 0;
$count = 0;
$key = '';
$citys = [];
$file1 = fopen($file_path1, 'r');
$file2 = fopen($file_path2, 'r');
$record = [];
$keys = [];
$file_path = explode('/', $file_path1);
$file3 = fopen(__DIR__ . '/data/download/' . $file_path[8], 'w');
while ($info = fgetcsv($file1)) {
if (empty($info[9])) {
$key = $info[1];
$keys[] = $key;
}
$data['name'] = $info[0];
$city = city_exist($citys,$info[1]);
$citys[] = $city;
$data['city'] = $city;
$data['supply'] = $info[2]??'';
$data['ip'] = $info[3]??'';
$data['daikuan'] = $info[4]??'';
$data['onlineuser'] = $info[5]??'';
$data['maxuser'] = $info[6]??'';
$data['online'] = $info[7]??'';
if (!empty($info[9])) {
$user_count += $data['online'] == '正常' ? 1 : 0;
$count++;
}
$data['status'] = $info[8]??'';
$ip = explode('.', ($info[9]??''));
$data['nasname'] = $ip[0] ? ip_repeat($record, $ip[0]) . '.' . $dns : '';
$list1[$key][] = $data;
}
while ($info = fgetcsv($file2)) {
if (empty($info[9])) {
$key = $info[1];
if (in_array($key, $keys)) {
continue;
}
}
$data['name'] = $info[0];
$city = city_exist($citys,$info[1]);
$citys[] = $city;
$data['city'] = $city;
$data['supply'] = $info[2]??'';
$data['ip'] = $info[3]??'';
$data['daikuan'] = $info[4]??'';
$data['onlineuser'] = $info[5]??'';
$data['maxuser'] = $info[6]??'';
$data['online'] = $info[7]??'';
if (!empty($info[9])) {
$user_count += $data['online'] == '正常' ? 1 : 0;
$count++;
}
$data['status'] = $info[8]??'';
$ip = explode('.', ($info[9]??''));
$data['nasname'] = $ip[0] ? ip_repeat($record, $ip[0]) . '.' . $dns : '';
$list1[$key][] = $data;
}
foreach ($list1 as $k => $val) {
foreach ($val as $net_data) {
fputcsv($file3, $net_data);
$list[] = $net_data;
}
}
fclose($file1);
fclose($file2);
fclose($file3);
echo json_encode(['data' => $list, 'count' => $count, 'use_count' => $user_count]);
}
function ip_repeat(&$record, $ip, $dns ='')
{
for ($i = 2; $i < 100; $i++) {
if (in_array($ip.$dns, $record)) {
if (in_array($ip .$dns. 'v' . $i, $record)) {
continue;
} else {
$record[] = $ip .$dns. 'v' . $i;
return $ip . 'v' . $i;
}
} else {
$record[] = $ip.$dns;
return $ip;
}
}
}
function city_exist($citys, $city)
{
for ($i = 2; $i < 100; $i++) {
if (in_array($city, $citys)) {
if (in_array($city . $i, $citys)) {
continue;
} else {
return $city . $i;
}
} else {
return $city;
}
}
}

View File

@@ -5,11 +5,12 @@
* @Author: kangkang
* @Date: 2020-11-03 11:04:15
* @LastEditors: Please set LastEditors
* @LastEditTime: 2020-11-26 09:48:10
* @LastEditTime: 2020-11-27 10:26:40
*/
$is_script = 1;
include __DIR__ . '/../../index.php';
include_once __DIR__ . '/../../index.php';
include_once __DIR__ . '/auto_format.php';
use app\api\model\Product;
$product_model = new Product;
$product_list = $product_model->field('Id,Token')->fetchAll();
@@ -103,6 +104,9 @@ fclose($file2288);
fclose($all);
fclose($dnx_exit);
sleep(5);
auto_format_list();
//强子服务器解析规则
function qiangzi_getList($data, &$file, &$all, $exit)
{