Not strong in php, please help. It is necessary to make sure that when the text NOW WATCHES appears on the site (it appears in the admin panel, if the user entered the site there was a sound signal, the sound file was played once). In this case, an update occurs every 5 seconds, the user is found, that is, when updating, if the function is hanged, it can be re-executed every 5 seconds. How to avoid it? I've been scratching my head for more than one day, I ask for help. Code below

<div class="metrics_info">  <?php echo $geo; ?>  <br>  <?php if((strtotime($value["date_view"]) + 180) > time()){ ?>  <span class="online badge-pulse-green-small"></span> are watching now
  <br>  <?php } ?>  <?php if($value["view_page_title"]){ ?>  <a title="<?php echo $value["view_page_title"]; ?>" target="_blank" href="<?php echo $value["view_page_link"]; ?>">    <?php echo custom_substr($value["view_page_title"],40, "..."); ?>  </a>  <?php }else{ ?>  <a title="<?php echo $value["view_page_link"]; ?>" target="_blank" href="<?php echo $value["view_page_link"]; ?>">    <?php echo custom_substr($value["view_page_link"],40, "..."); ?>  </a>  <?php } ?></div>
  • Answer # 1

    You can add a function definitionbeep, and if you want to play a sound, add to the page output .

    <!--Add this code once per page --><script>const audioCtx= new(window.AudioContext || window.webkitAudioContext || window.audioContext);
     * @param {number} duration Sound duration
     * @param {number} frequency Audio frequency
     * @param {number} volume Audio playback volume
     * @param {string} type Oscillator type
     * @param {function} callback Asynchronous return function
    function beep(duration, frequency, volume, type, callback) {
        var oscillator= audioCtx.createOscillator();
        var gainNode= audioCtx.createGain();
        oscillator connect(gainNode);
        if (volume){gainNode.gain.value= volume;}
        if (frequency){oscillator.frequency.value= frequency;}
        if (type){oscillator.type= type;}
        if (callback){oscillator.onended= callback;}
        oscillator.stop(audioCtx.currentTime + ((duration || 500) /1000));
    &lt;/script&gt;&lt;!--And this code can be used many times --&gt;&lt;script&gt;beep()
    &lt;/script&gt;   &lt;button onclick="beep()"&gt; Play&lt;/button&gt;

    A source

    In principle, it is clear, but how to change the sound to your own? I can not find !

    Андрей Черемушкин2022-01-22 17:16:45

    Ah, well, this is a sequencer, by changing the frequency you can achieve interesting sounds. For example, the tone dial buttons on a telephone produce sounds of frequencies: 1= 700/900 2= 700/1100 3= 900/1100 4= 700/1300 5= 900/1300 6= 1100/1300 7= 700/1500 8= 900/1500 9= 1100/1500 0= 1300/1500 #= 700/1700 *= 1300/1700

    DiD2022-01-22 17:35:51

    Works only in this sequence now they watch , but the data about the user on the site is updated every 5 seconds, AND every 5 seconds there is a sound !! I don't understand how to solve this

    Андрей Черемушкин2022-01-22 18:56:41

    I would like to consider the option with personal sounds in the form of mp3 for notification. Your variant works but something is wrong in the function call.

    Андрей Черемушкин2022-01-22 19:02:30