Commit 1cceb9f9 by san58

обвязка логированием

1 parent 4c88ee32
...@@ -60,9 +60,12 @@ class ScanController extends Controller ...@@ -60,9 +60,12 @@ class ScanController extends Controller
$filters = ['1'=>Collection::get_filter(Filter::TYPE_1), '2'=>Collection::get_filter(Filter::TYPE_2), '3'=>Collection::get_filter(Filter::TYPE_3)]; $filters = ['1'=>Collection::get_filter(Filter::TYPE_1), '2'=>Collection::get_filter(Filter::TYPE_2), '3'=>Collection::get_filter(Filter::TYPE_3)];
$csv_datatime = ''; $csv_datatime = '';
$progress = 0; $progress = 0;
while (($csv_data = fgetcsv($csv_handle, 1024, ';')) !== false) $time_start = 0;
while (($csv_data = fgetcsv($csv_handle, 1024, ';')) !== false && $csv_row<2920)
{ {
if ($csv_row === 2900){ $time_cuttent = microtime(true); echo "\n".'t1 '.($time_cuttent - $time_start)."\n";$time_start = $time_cuttent;}
$file_pos = ftell($csv_handle); $file_pos = ftell($csv_handle);
if ($csv_row === 2900){ $time_cuttent = microtime(true); echo 't2 '.($time_cuttent - $time_start)."\n";$time_start = $time_cuttent;}
if ($file_pos !== false && $file_size>0) if ($file_pos !== false && $file_size>0)
{ {
$progress_current = (int)round(10*$file_pos/$file_size); $progress_current = (int)round(10*$file_pos/$file_size);
...@@ -74,6 +77,7 @@ class ScanController extends Controller ...@@ -74,6 +77,7 @@ class ScanController extends Controller
unset($progress_current); unset($progress_current);
} }
if ($csv_row === 2900){ $time_cuttent = microtime(true); echo 't3 '.($time_cuttent - $time_start)."\n";$time_start = $time_cuttent;}
$csv_row++; $csv_row++;
if ($csv_row===1) if ($csv_row===1)
$csv_datatime = date( $csv_datatime = date(
...@@ -84,17 +88,24 @@ class ScanController extends Controller ...@@ -84,17 +88,24 @@ class ScanController extends Controller
); );
elseif (isset($csv_data[1])===true) elseif (isset($csv_data[1])===true)
{ {
if ($csv_row === 2901){ $time_cuttent = microtime(true); echo 't4 '.($time_cuttent - $time_start)."\n";$time_start = $time_cuttent;}
$host = Collection::domain_filter($csv_data[1]); $host = Collection::domain_filter($csv_data[1]);
if ($csv_row === 2901){ $time_cuttent = microtime(true); echo 't5 '.($time_cuttent - $time_start)."\n";$time_start = $time_cuttent;}
if ($host === false) if ($host === false)
$csv_skip_row++; {
$csv_skip_row++;
}
else else
{ {
if ($csv_row === 2901){ $time_cuttent = microtime(true); echo 't6 '.($time_cuttent - $time_start)."\n";$time_start = $time_cuttent;}
$status = [ $status = [
'1'=>(Collection::apply_filter($host, $filters['1'])===false?Host::STATUS_OFF:Host::STATUS_ON), '1'=>(Collection::apply_filter($host, $filters['1'])===false?Host::STATUS_OFF:Host::STATUS_ON),
'2'=>(Collection::apply_filter($host, $filters['2'])===false?Host::STATUS_OFF:Host::STATUS_ON), '2'=>(Collection::apply_filter($host, $filters['2'])===false?Host::STATUS_OFF:Host::STATUS_ON),
'3'=>(Collection::apply_filter($host, $filters['3'])===false?Host::STATUS_OFF:Host::STATUS_ON) '3'=>(Collection::apply_filter($host, $filters['3'])===false?Host::STATUS_OFF:Host::STATUS_ON)
]; ];
if ($csv_row === 2901){ $time_cuttent = microtime(true); echo 't7 '.($time_cuttent - $time_start)."\n";$time_start = $time_cuttent;}
$db_request = Yii::$app->db->createCommand(); $db_request = Yii::$app->db->createCommand();
if ($csv_row === 2901){ $time_cuttent = microtime(true); echo 't8 '.($time_cuttent - $time_start)."\n";$time_start = $time_cuttent;}
if ($db_request) if ($db_request)
{ {
$host_bd = (new Query()) $host_bd = (new Query())
...@@ -103,6 +114,7 @@ class ScanController extends Controller ...@@ -103,6 +114,7 @@ class ScanController extends Controller
->where('domain=:host', array(':host'=>$host)) ->where('domain=:host', array(':host'=>$host))
->limit(1) ->limit(1)
->one(); ->one();
if ($csv_row === 2901){ $time_cuttent = microtime(true); echo 't9 '.($time_cuttent - $time_start)."\n";$time_start = $time_cuttent;}
if ( $host_bd === false ) if ( $host_bd === false )
{ {
$db_request->insert( $db_request->insert(
...@@ -118,9 +130,11 @@ class ScanController extends Controller ...@@ -118,9 +130,11 @@ class ScanController extends Controller
] ]
)->execute(); )->execute();
$rec['insert']++; $rec['insert']++;
if ($csv_row === 2901){ $time_cuttent = microtime(true); echo 't10 '.($time_cuttent - $time_start)."\n";$time_start = $time_cuttent;}
} }
elseif (isset($host_bd['csv_date']) && $host_bd['csv_date'] !== $csv_datatime) elseif (isset($host_bd['csv_date']) && $host_bd['csv_date'] !== $csv_datatime)
{ {
if ($csv_row === 2901){ $time_cuttent = microtime(true); echo 't11 '.($time_cuttent - $time_start)."\n";$time_start = $time_cuttent;}
$db_request->update( $db_request->update(
'{{%host}}', '{{%host}}',
[ [
...@@ -134,19 +148,24 @@ class ScanController extends Controller ...@@ -134,19 +148,24 @@ class ScanController extends Controller
] ]
)->execute(); )->execute();
$rec['update']++; $rec['update']++;
if ($csv_row === 2901){ $time_cuttent = microtime(true); echo 't12 '.($time_cuttent - $time_start)."\n";$time_start = $time_cuttent;}
} }
unset($host_bd); unset($host_bd);
if ($csv_row === 2901){ $time_cuttent = microtime(true); echo 't13 '.($time_cuttent - $time_start)."\n";$time_start = $time_cuttent;}
} }
else else
echo PHP_EOL.$this->ansiFormat('! Error create DB request'); echo PHP_EOL.$this->ansiFormat('! Error create DB request');
unset($db_request); unset($db_request);
unset($status); unset($status);
if ($csv_row === 2901){ $time_cuttent = microtime(true); echo 't14 '.($time_cuttent - $time_start)."\n";$time_start = $time_cuttent;}
} }
unset($host); unset($host);
if ($csv_row === 2901){ $time_cuttent = microtime(true); echo 't15 '.($time_cuttent - $time_start)."\n";$time_start = $time_cuttent;}
} }
else else
$csv_skip_row++; $csv_skip_row++;
unset($file_pos); unset($file_pos);
if ($csv_row === 2901){ $time_cuttent = microtime(true); echo 't16 '.($time_cuttent - $time_start)."\n";$time_start = $time_cuttent;}
} }
unset($progress); unset($progress);
unset($csv_data); unset($csv_data);
......
...@@ -32,11 +32,11 @@ class Collection extends Component ...@@ -32,11 +32,11 @@ class Collection extends Component
$host_parts = array_reverse($host_parts); $host_parts = array_reverse($host_parts);
$host_parts = array_slice($host_parts, 0, 2); $host_parts = array_slice($host_parts, 0, 2);
$host_parts = array_reverse($host_parts); $host_parts = array_reverse($host_parts);
if (count($host_parts) === 2) if (count($host_parts) === 2)
$out = $host; $out = implode('.', $host_parts);
unset($host_parts); unset($host_parts);
} }
unset($host); unset($host);
return $out; return $out;
} }
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!