Page MenuHomePhorge

DBPing.php
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

DBPing.php

<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class DBPing extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'db:ping {--wait}';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Ping the database [and wait for it to respond]';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
if ($this->option('wait')) {
while (true) {
try {
$result = DB::select("SELECT 1");
if (sizeof($result) > 0) {
break;
}
} catch (\Exception $exception) {
sleep(1);
}
}
} else {
try {
$result = DB::select("SELECT 1");
return 0;
} catch (\Exception $exception) {
return 1;
}
}
}
}

File Metadata

Mime Type
text/x-php
Expires
Fri, Apr 24, 10:21 AM (13 h, 2 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
35/87/8ad7fa45b8ccf36d93c6bac91858
Default Alt Text
DBPing.php (1 KB)

Event Timeline