walkor / workerman

An asynchronous event driven PHP socket framework. Supports HTTP, Websocket, SSL and other custom protocols.
http://www.workerman.net
MIT License
11.03k stars 2.25k forks source link

How to start script many times at same time #1004

Closed xenion54 closed 5 months ago

xenion54 commented 5 months ago

On windows i can run script with same name multiple times (with different params). On linux, this doesn't work. After start first script, others scripts not starting. Event onWorkerStart called just first time. How can i run same script multiple times in linux?

<?php

use Workerman\Connection\TcpConnection;

require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Libs' . DIRECTORY_SEPARATOR . 'init.php';

$args = getopt('', ['port:']);

global $argv;

$argv[1] = 'start';
$argv[2] = '-d';

$sw = new \Workerman\Worker('websocket://0.0.0.0:' . $args['port']);
$sw->count = 1;

$sw->onWorkerStart = function (\Workerman\Worker $worker) {
    echo $args['arg1'] . PHP_EOL; // this line called only once
};

\Workerman\Worker::runAll();
walkor commented 5 months ago
<?php
use Workerman\Connection\TcpConnection;

require_once dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Libs' . DIRECTORY_SEPARATOR . 'init.php';

$args = getopt('', ['port:']);

global $argv;

$argv[1] = 'start';
$argv[2] = '-d';

// The key
\Workerman\Worker::$pidFile= __DIR__ . '/worker.' . $args['port'] . '.pid';
$sw = new \Workerman\Worker('websocket://0.0.0.0:' . $args['port']);
$sw->count = 1;

$sw->onWorkerStart = function (\Workerman\Worker $worker) {
    echo $args['arg1'] . PHP_EOL; // this line called only once
};

\Workerman\Worker::runAll();
xenion54 commented 5 months ago

@walkor thx, its work