I want to show a sound notification in admin dashboard without page load whenever user place a new order from front end. please help me regarding this I have spend many hours on internet but didn't find any solution yet. Or any suggestions how can it possible notifications process in PHP ?
Asked
Active
Viewed 1,071 times
2
-
2you may have a listener code on your admin page that will fire an AJAX request to Server After every n seconds ( 1 < n < 4 ) to see whether any new entry has arrived into the table or not. – Shubhranshu Sep 06 '17 at 11:21
1 Answers
1
My advice would be to use Pusher. You can sign up for a free account with them (pusher.com). They provide some very simple code to get your started.
Step 1 - trigger this code when a new order is placed:
<?php
require __DIR__ . '/vendor/autoload.php';
$options = array(
'cluster' => 'eu',
'encrypted' => true
);
$pusher = new Pusher\Pusher(
'xxxx',
'xxxx',
'xxxx',
$options
);
$data['message'] = 'hello world';
$pusher->trigger('my-channel', 'my-event', $data);
?>
Obviously you can change the contents of the array to "push" whatever data you like.
Step 2 - code to receive the push in your admin dashboard
<!DOCTYPE html>
<head>
<title>Pusher Test</title>
<script src="https://js.pusher.com/4.1/pusher.min.js"></script>
<script>
// Enable pusher logging - don't include this in production
Pusher.logToConsole = true;
var pusher = new Pusher('xxxx', {
cluster: 'eu',
encrypted: true
});
var channel = pusher.subscribe('my-channel');
channel.bind('my-event', function(data) {
alert(data.message);
});
</script>
</head>
So, when you send a push then it will be alerted by this code.
You could then change the alert to actually play a sound. There are plenty of posts on here about how you can achieve this, for example Playing sound notifications using Javascript?

Chris
- 4,672
- 13
- 52
- 93