Build a High‑Performance Webman Project on ServBay in Minutes
This guide walks you through installing Webman on ServBay, configuring routes, controllers, and multiple databases, then running the project to demonstrate high‑concurrency PHP web applications with real‑time API endpoints.
Webman is a high‑performance PHP asynchronous web framework built on Workerman, designed for high‑concurrency web applications and APIs. Unlike traditional synchronous frameworks, it uses event‑driven, non‑blocking I/O, offering a simple API and extensible plugin system.
Installation on ServBay
ServBay already includes Composer, so no separate installation is needed. Create a project directory under /Applications/ServBay/www, then run:
composer create-project workerman/webman servbay-webman-app
cd servbay-webman-appInstall additional components required for database, pagination, events, and debugging:
composer require -W illuminate/database illuminate/redis illuminate/pagination illuminate/events symfony/var-dumperWriting the Web Project Code
Configure Routes
Add the following to config/route.php to define basic routes for index, cache, Redis, MySQL, and PostgreSQL operations:
use Webman\Route;
use app\controller\IndexController;
use app\controller\CacheController;
use app\controller\DatabaseController;
Route::any('/', [IndexController::class, 'index']);
Route::any('/memcached', [CacheController::class, 'memcached']);
Route::any('/redis', [CacheController::class, 'redis']);
Route::any('/mysql-add', [DatabaseController::class, 'mysqlAdd']);
Route::any('/mysql', [DatabaseController::class, 'mysqlGet']);
Route::any('/pgsql-add', [DatabaseController::class, 'pgsqlAdd']);
Route::any('/pgsql', [DatabaseController::class, 'pgsqlGet']);Create Controllers
In app/controller create three files.
IndexController.php :
namespace app\controller;
use support\Request;
class IndexController {
public function index(Request $request) {
return response('Hello ServBay!');
}
}CacheController.php (demonstrates Memcached and Redis):
namespace app\controller;
use support\Request;
use support\Response;
use Memcached;
use support\Redis;
class CacheController {
public function memcached(Request $request): Response {
$memcached = new Memcached();
$memcached->addServer('127.0.0.1', 11211);
$memcached->set('key', 'Hello Memcached!', 60);
$value = $memcached->get('key');
return response($value);
}
public function redis(Request $request): Response {
Redis::set('key', 'Hello Redis!');
$value = Redis::get('key');
return response($value);
}
}DatabaseController.php (MySQL and PostgreSQL CRUD examples):
namespace app\controller;
use support\Request;
use support\Response;
use support\Db;
class DatabaseController {
public function mysqlAdd(Request $request): Response {
DB::connection('mysql')->table('users')->insert([
'name' => 'Webman',
'email' => '[email protected]',
]);
return response('User added');
}
public function mysqlGet(Request $request): Response {
$users = DB::connection('mysql')->table('users')->get();
return response(json_encode($users));
}
public function pgsqlAdd(Request $request): Response {
DB::connection('pgsql')->table('users')->insert([
'name' => 'Webman',
'email' => '[email protected]',
]);
return response('User added');
}
public function pgsqlGet(Request $request): Response {
$users = DB::connection('pgsql')->table('users')->get();
return response(json_encode($users));
}
}Database Configuration
Edit config/database.php to set connection details for MySQL and PostgreSQL (host, port, database, username, password, charset, etc.).
Running the Project
Start the server from the project root: php start.php start Access the following URLs to verify functionality: http://localhost:8787 – displays
Hello ServBay! http://localhost:8787/memcached– displays
Hello Memcached! http://localhost:8787/redis– displays
Hello Redis! http://localhost:8787/mysql-add– adds a MySQL user and returns
User added http://localhost:8787/mysql– returns the MySQL users list http://localhost:8787/pgsql-add – adds a PostgreSQL user http://localhost:8787/pgsql – returns the PostgreSQL users list
Conclusion
Following these steps you can quickly create and run a Webman project on ServBay, leveraging its high performance and easy‑to‑use API to handle concurrent requests, integrate multiple databases, and build robust web services.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
