How to start, stop workerman from web browser?
Hi, again ) How to realize full work cycle of workerman from web page (php/nginx) ? php-fpm start with low privileged user wwwdata If I understood correctly, workerman works correctly only from root. But I really want to press the beautiful start-stop buttons in the browser, and not typing in the console. Thanks.
Set the user of the worker processes. You can see https://github.com/walkor/workerman/issues/139#issuecomment-277579184
Bad luck. Can`t start any simple workerman in background from php-fpm/nginx script. My task is to start and stop a large number of workers from the web interface that perform different tasks. Now I see only one (bad?) way : Create one other (root) worker that will be start/stop other :) and manage it from asyncTcpConnecton Any ideas?
- Create
wk-manager.phpfile in your php-fpm project.
<?php
// This is just a simple example, please note for security verification.
$action = $_GET['action'] ?? null;
if (!empty($action) && in_array($action,['start','stop','status'])) {
if ($action === 'start') {
$action = "$action -d";
}
// You can get the static-php-cli bin file from https://www.workerman.net/download
$cmd = "/your/path/of/workerman-app/php /your/path/of/workerman-app/start.php $action";
// Don't forget to enable exec function in php.ini
exec($cmd,$output);
echo "<pre>";
print_r($output);
echo "</pre>";
} else {
header('HTTP/1.1 400 Bad Request');
echo '400 Bad Request';
}
- An http server
<?php
// start.php
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
use Workerman\Protocols\Http\Request;
require_once __DIR__ . '/vendor/autoload.php';
$http_worker = new Worker("http://0.0.0.0:2345");
// Set the user of worker processes.
$http_worker->user = 'www'; // www is my running user for php-fpm and nginx.
$http_worker->count = 4;
$http_worker->onMessage = function(TcpConnection $connection, Request $request)
{
$connection->send('hello world');
};
Worker::runAll();
- Some results:
If you are worried about the security risks of opening the exec function, you can use workerman to start an http server (restapi) with local access only, and then just access the restapi to manage your workerman.
Thanks, seems like it works ) Why i must use static cimpiled php-cli ? I tested with my dynamic php8.1 (out of the box) ant it works too.
It's not required, it's a workerman out-of-the-box runtime environment, and with it you'll no longer need to install various php environments and event and such extensions on your server. You can also package it with your workerman project and run it on a linux server that doesn't have php installed.