PHP code example of easyswoole / wsdebug

1. Go to this page and download the library: Download easyswoole/wsdebug 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/ */

    

easyswoole / wsdebug example snippets


// 在路由里注册个访问地址
// App/HttpController/Router.php

namespace App\HttpController;

use FastRoute\RouteCollector;
use EasySwoole\Core\Http\Request;
use EasySwoole\Core\Http\Response;
use EasySwoole\Core\Swoole\ServerManager;


class Router extends \EasySwoole\Core\Http\AbstractInterface\Router
{
	function register( RouteCollector $routeCollector )
	{
		$routeCollector->get( '/wsdebug', function( Request $request, Response $response ){
			$wsdebug = new \wsdebug\WsDebug();
			// 设置 swoole 服务
			$wsdebug->setServer( ServerManager::getInstance()->getServer() );
			// 设置输出html里的websocket服务地址
			$wsdebug->setHost( 'ws://127.0.0.1:9501' );
			// 输出调试工具的html
			$response->write( $wsdebug->getHtml() );
			$response->end();
		} );
	}
}


$wsdebug = new \wsdebug\WsDebug();
$wsdebug->send(['错误信息'=>'我是错误信息,为了测试输出到前台'],'error');