-
Name the file using the pattern start_ followed by your service name (lowercase, underscores) and place it in the Applications/Chat/ directory. The service name becomes the key added to $services in start.php.
-
Write the file using this exact boilerplate:
<?php
use \Workerman\Worker;
use \Workerman\Connection\TcpConnection;
if (ini_get('default_socket_timeout') < 1200 && ini_get('default_socket_timeout') > 1) {
ini_set('default_socket_timeout', 1200);
}
if (!defined('GLOBALDATA_IP')) {
require_once '/home/my/include/config/config.settings.php';
}
$worker = new Worker('<protocol>://0.0.0.0:<port>');
$worker->name = '<ServiceName>';
$worker->count = 5;
$worker->onConnect = function ($connection) {
$connection->maxSendBufferSize = 100*1024*1024;
$connection->maxPackageSize = 100*1024*1024;
};
$worker->onBufferFull = function ($connection) {
Worker::safeEcho("<ServiceName> bufferFull and do not send again\n");
};
$worker->onBufferDrain = function ($connection) {
Worker::safeEcho("<ServiceName> buffer drain and continue send\n");
};
$worker->onError = function ($connection, $code, $msg) {
Worker::safeEcho("<ServiceName> error {$code} {$msg}\n");
};
if (!defined('GLOBAL_START')) {
Worker::runAll();
}
Replace <protocol> (websocket, text, http), <port>, and <ServiceName> for the new service.
Verify the file exists in Applications/Chat/ before proceeding.
-
Add extra use-statements only if needed (e.g., use \GatewayWorker\BusinessWorker; for GatewayWorker types). Follow the import order in existing files: Workerman core first, then GatewayWorker, then GlobalData.
-
Add onWorkerStart if the service needs initialization (DB connections, loading configs, registering with GlobalData). Model after Applications/Chat/start_task.php onWorkerStart for resource setup.
-
Register in start.php — open start.php and add '<service_name>' to $services:
- Standard service (runs on all hosts): add to the base array on line 33.
$services = ['task', 'gateway', 'gateway_ssl', 'businessworker', 'web', '<service_name>'];
- myadmin1-only service: add to the
array_merge branch on line 35.
$services = array_merge(['globaldata', 'channel', 'register', '<service_name>'], $services);
Verify start.php line 33–35 reflects the change before proceeding.
-
Validate the new service loads without errors:
php start.php start -d
Look for <ServiceName> in the process list and confirm no PHP parse errors in /home/my/logs/billingd.log.
-
PHP Fatal error: Class 'Workerman\Worker' not found — the file was run directly without vendor/autoload.php. The autoloader is loaded by start.php, so either run via php start.php start or add require_once __DIR__ . '/../../vendor/autoload.php'; for standalone testing.
-
Worker starts but is missing from process list — '<service_name>' was not added to $services in start.php. Check lines 33–35 of start.php.
-
Address already in use on chosen port — the port conflicts with an existing service. Current port assignments: 1236 (register), 2207 (globaldata), 2208 (task), 3333 (channel), 7271 (gateway), 7272 (gateway SSL), 55151 (web). Choose a port outside this list.
-
Service runs standalone but crashes under start.php — missing GLOBAL_START guard at the bottom. Ensure the file ends with if (!defined('GLOBAL_START')) { Worker::runAll(); }.
-
GLOBALDATA_IP undefined — config was not loaded. Ensure the guard block if (!defined('GLOBALDATA_IP')) { require_once '/home/my/include/config/config.settings.php'; } appears before any use of the constant.