-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackend.php
25 lines (22 loc) · 855 Bytes
/
backend.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
require 'config.php';
require 'vendor/autoload.php'; // include Composer goodies
require 'classes/isitup.php';
//Get the url from POST request
$url = isset($_POST['url'])?$_POST['url']:null;
//create new object from is it up class
$isitup = new isitup($url);
//check on the status of the url
$isitupResult = $isitup->check();
try {
//connect to mongo DB
$mongoClient = new MongoDB\Client(MONGODB_URL);
//select the DB and collection that we will work on
$historyCollection = $mongoClient->{MONGODB_NAME}->{MONGODB_COLLECTION};
//Insert new document in the collection with the result of the check
$result = $historyCollection->insertOne( [ 'url' => $isitupResult['url'], 'status' => $isitupResult['status'], 'time' => time() ] );
} catch (Exception $e) {
//Do nothing :D
}
//display the result to the user
echo json_encode($isitupResult);