Skip to content

Commit

Permalink
update snatch method
Browse files Browse the repository at this point in the history
  • Loading branch information
copyrenzhe committed Feb 4, 2017
1 parent 283bdb5 commit 80bbf99
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 1 deletion.
61 changes: 61 additions & 0 deletions app/Console/Commands/SiteMonitor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Console\Commands;

use App\Events\Event;
use App\Events\MailPostEvent;
use Illuminate\Console\Command;

class SiteMonitor extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'monitor:site';

/**
* The console command description.
*
* @var string
*/
protected $description = '(Maple) Monitor the site`s status';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$url = config('url');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$output = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode===200){
session(['siteMonitor' => 0]);
} else {
$error_times = session('siteMonitor') + 1;
session(['siteMonitor' => $error_times]);
}
//连续一个小时访问异常
if(session('siteMonitor') > 5){
Event::fire(new MailPostEvent('system', '网站访问异常', array()));
session(['siteMonitor' => 0]);
}
}
}
5 changes: 5 additions & 0 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class Kernel extends ConsoleKernel
Commands\RepairData::class,
Commands\SumOfChapters::class,
Commands\CompareQidianNovel::class,
Commands\SiteMonitor::class,
];

/**
Expand Down Expand Up @@ -58,6 +59,10 @@ protected function schedule(Schedule $schedule)
->monthlyOn(28, '21:00');
$schedule->command('compare:qidian fin 2 --queue')
->monthlyOn(28, '22:00');

//站点可访问性监控
$schedule->command('monitor:site')
->everyTenMinutes();
//
//每天更新所有小说章节数
// $schedule->command('sum:chapter --queue')
Expand Down
3 changes: 3 additions & 0 deletions app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
|
*/

Route::get('test', function(){

});

Route::group(['prefix' => 'admin', 'middleware' => ['web'], 'namespace' => 'Admin'], function(){
Route::get('login', 'AuthController@getLogin');
Expand Down
2 changes: 1 addition & 1 deletion app/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function async_get_url($urls, $append_url='', $page_size=500, $source_encode='gb
*/
if(!function_exists('is_weixin')) {
function is_weixin(){
if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {
if ( strpos(@$_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {
return true;
}
return false;
Expand Down
1 change: 1 addition & 0 deletions resources/views/emails/system.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
这是一封系统邮件,收到这封邮件代表网站系统可能出现了问题。

0 comments on commit 80bbf99

Please sign in to comment.