update is_connected with dynamic server
This commit is contained in:
parent
5450124be9
commit
476f01098f
|
@ -85,7 +85,10 @@ class ApiController extends Controller {
|
|||
$ip = "https://dev-dc.beetai.com";
|
||||
if ($server_ip)
|
||||
$ip = $server_ip->data;
|
||||
if ($this->is_connected() && $logs) {
|
||||
$parseUrl = parse_url($ip);
|
||||
$host = $parseUrl['host'];
|
||||
$port = isset($parseUrl['port']) ? $parseUrl['port'] : 80;
|
||||
if ($this->is_connected($host, $port) && $logs) {
|
||||
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
|
||||
$id_camera = 0;
|
||||
if ($device_id)
|
||||
|
@ -337,17 +340,19 @@ class ApiController extends Controller {
|
|||
|
||||
public function actionSync() {
|
||||
Yii::$app->response->format = "json";
|
||||
if ($this->is_connected()) {
|
||||
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
|
||||
$ip = "https://dev-dc.beetai.com";
|
||||
if ($server_ip)
|
||||
$ip = $server_ip->data;
|
||||
$server_ip = \app\models\SyncUrl::findOne(['key_config' => 'server_api']);
|
||||
$ip = "https://dev-dc.beetai.com";
|
||||
if ($server_ip)
|
||||
$ip = $server_ip->data;
|
||||
$parseUrl = parse_url($ip);
|
||||
$host = $parseUrl['host'];
|
||||
$port = isset($parseUrl['port']) ? $parseUrl['port'] : 80;
|
||||
if ($this->is_connected($host, $port)) {
|
||||
$device_id = \app\models\SyncUrl::findOne(['key_config' => 'device_id']);
|
||||
$id_camera = 0;
|
||||
if ($device_id)
|
||||
$id_camera = intval($device_id->data);
|
||||
$ls = CaptureLogs::find()->andWhere(['sync_status' => null])->all();
|
||||
|
||||
$tk = "";
|
||||
$token = \app\models\SyncUrl::findOne(['key_config' => 'token']);
|
||||
if ($token)
|
||||
|
@ -384,9 +389,9 @@ class ApiController extends Controller {
|
|||
return ["status" => true];
|
||||
}
|
||||
|
||||
function is_connected($ip = "google.com") {
|
||||
$connected = @fsockopen($ip, 80);
|
||||
//website, port (try 80 or 443)
|
||||
function is_connected($host, $port) {
|
||||
$connected = @fsockopen($host, $port);
|
||||
//website, port (try 80 or 443)
|
||||
if ($connected) {
|
||||
$is_conn = true; //action when connected
|
||||
fclose($connected);
|
||||
|
|
Loading…
Reference in New Issue
Block a user