1. Go to this page and download the library: Download easyswoole/console 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 / console example snippets
use EasySwoole\Console\Console;
use EasySwoole\Console\ModuleInterface;
$http = new swoole_http_server("127.0.0.1", 9501);
$http->on("request", function ($request, $response) {
$response->header("Content-Type", "text/plain");
$response->end("Hello World\n");
});
/*
* 开一个tcp端口给console 用
*/
$tcp = $http->addlistener('0.0.0.0',9600,SWOOLE_TCP);
/*
* 实例化一个控制台,设置密码为123456
*/
$console = new Console('myConsole','123456');
/*
* 定义自己的一个命令
*/
class Test implements ModuleInterface
{
public function moduleName(): string
{
return 'test';
}
public function exec(array $arg, int $fd, Console $console)
{
return 'this is test exec';
}
public function help(array $arg, int $fd, Console $console)
{
return 'this is test help';
}
}
/*
* 命令注册
*/
$console->moduleContainer()->set(new Test());
/*
* 依附给server
*/
$console->protocolSet($tcp)->attachToServer($http);
$http->start();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.