0
<?php

session_start();

$con = mysqli_connect('localhost', 'root');

mysqli_select_db($con, 'id12887901_visitor');

$query = "select * from curvis1 order by id desc limit 1";
$result = mysqli_query($con, $query);
$row = mysqli_fetch_array($result);

date_default_timezone_set('Asia/Hong_Kong');
$today = date("H:i:s");
  echo $today;  

if ($today == $row['end_at']){
  $msg = "Visitor No.1 pass has expired.";
  $reg = "insert into msg(comment) values('$msg')";
  mysqli_query($con, $reg);
  echo "WTF";

} else  {
  echo "LOL";

}


?>

I want it to run in the background. I've head of using ajax but alas I have not found an ajax solution in this. Any feedback will be appreciated thank you.

This is for a notification.

How do i call the server by ajax and asking frequently if there's any changes etc.

  • If you want to run this completely in the background (without the webserver) on a timed schedule (e.g. every 5 minutes, or something), then configure a Cron job on your server (or Windows Scheduled Task, if your server runs Windows) to execute this PHP script automatically. – ADyson Mar 22 '20 at 22:40
  • Just seen your edit: _"How do i call the server by ajax"_ ... you can use `setInterval()` in your Javascript to fire an AJAX request at a certain interval (e.g. every 5 minutes). You can easily google examples of both using setInterval, and using AJAX requests. Or, if you prefer, you could do it the other way round and have the server notify the browser using Server-Sent Events (SSE) or Websockets. This can be more efficient in some situations. Have you researched or tried anything yet in relation to your requirement? – ADyson Mar 22 '20 at 22:41
  • Does this answer your question? [jQuery, simple polling example](https://stackoverflow.com/questions/6835835/jquery-simple-polling-example) – ArSeN Mar 22 '20 at 23:03

1 Answers1

0

Cron did the job for me after learning it! sorry for the dumb question guys.