Exemple #1
0
<?php

include '../src/speaker.php';
class Test extends SpeakerEvents
{
    function update()
    {
        return 'ok';
    }
    function check()
    {
        return true;
    }
}
$speaker = new Speaker();
$speaker->addListener('', new Test());
$speaker->start();
Exemple #2
0
<?php

include '../../src/speaker.php';
class SystemLoad extends SpeakerEvents
{
    function update()
    {
        return '一分前: ' . sys_getloadavg()[0] . ', 五分前: ' . sys_getloadavg()[1] . ', 十五分前: ' . sys_getloadavg()[2];
    }
    function check()
    {
        return true;
    }
}
$speaker = new Speaker();
$speaker->sleepTime = 2;
$speaker->addListener('', new SystemLoad());
$speaker->start();
Exemple #3
0
        array_push($chat, $_GET['content']);
    } else {
        $chat = [$_GET['content']];
    }
    file_put_contents('chat.json', json_encode($chat));
} else {
    class Chatroom extends SpeakerEvents
    {
        private $chat = '';
        function __construct()
        {
            $this->chat = file_get_contents('chat.json');
        }
        function update()
        {
            return end(json_decode($this->chat));
        }
        function check()
        {
            $newestChat = file_get_contents('chat.json');
            if ($newestChat == $this->chat) {
                return false;
            }
            $this->chat = $newestChat;
            return true;
        }
    }
    $speaker = new Speaker();
    $speaker->addListener('', new Chatroom());
    $speaker->start();
}