瀏覽代碼

tested customize processes

mx 3 年之前
父節點
當前提交
45becf5e83
共有 4 個文件被更改,包括 59 次插入1 次删除
  1. 4 0
      README.md
  2. 11 1
      config/process.php
  3. 28 0
      process/TcpServer.php
  4. 16 0
      process/WorkerLogCleaner.php

+ 4 - 0
README.md

@@ -58,3 +58,7 @@ NOTICE
 
 see [official doc](https://www.workerman.net/doc/webman/plugin/console.html)
 
+### Custormized Processes
+
+see [https://www.workerman.net/doc/webman/process.html](https://www.workerman.net/doc/webman/process.html)
+

+ 11 - 1
config/process.php

@@ -33,5 +33,15 @@ return [
                 'php', 'html', 'htm', 'env'
             ]
         ]
-    ]
+    ],
+    'websocket' => [
+        'handler' => process\TcpServer::class,
+        'listen' => 'websocket://0.0.0.0:8888',
+        'count' => 1,
+    ],
+    // 'log_cleaner' => [
+    //     'handler' => process\WorkerLogCleaner::class,
+    // ]
 ];
+
+// see [https://www.workerman.net/doc/webman/process.html](https://www.workerman.net/doc/webman/process.html)

+ 28 - 0
process/TcpServer.php

@@ -0,0 +1,28 @@
+<?php
+
+namespace process;
+
+use Workerman\Connection\TcpConnection;
+
+class TcpServer
+{
+	public function onConnect(TcpConnection $conn)
+	{
+		echo 'onConnect\n';
+	}
+
+	public function onWebSocketConnect(TcpConnection $conn, $http_buffer)
+	{
+		echo 'onWebSocketConnect\n';
+	}
+
+	public function onMessage(TcpConnection $conn, $data)
+	{
+		$conn->send($data);
+	}
+
+	public function onClose($value='')
+	{
+		echo 'onClose\n';
+	}
+}

+ 16 - 0
process/WorkerLogCleaner.php

@@ -0,0 +1,16 @@
+<?php
+
+namespace process;
+
+use Workerman\Timer;
+use support\Db;
+
+class WorkerLogCleaner
+{
+	public function onWorkerStart()
+	{
+		Timer::add(10, function(){
+			echo 'Removing log...';
+		});
+	}
+}