PHP code example of anlity / yii2-swoole-async-timer
1. Go to this page and download the library: Download anlity/yii2-swoole-async-timer library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace common\components;
use anlity\swooleAsyncTimer\SocketInterface;
use anlity\swooleAsyncTimer\SwooleAsyncTimerComponent;
class SwooleAsyncTimer extends SwooleAsyncTimerComponent implements SocketInterface {
public function timerCallback($timerId, $server){
// 定时器的回调逻辑
}
public function onWorkerStart($server, $workerId){
}
public function onWorkerStop($server, $workerId){
}
public function onOpen($fd){
// 与客户端握手时的逻辑,可以把$fd写入到session或者缓存中
}
public function onClose($fd){
// 与客户端断开连接时的逻辑
}
public function onMessage($fd, $data){
// 收到客户端的消息的逻辑
}
}