About the invocation mode of using workerman in conjunction with codeigniter

excuse me, what should I do if workerman is enabled through PHP frameworks such as TP or CI, but some configuration files in the framework use the $_ SERVER constant, and failure to get $_ SERVER in CLI mode will cause an error?

class Mqtt extends CI_Controller {
    public function index()
    {
        $worker = new Worker();
        $worker->onWorkerStart = function(){
            $mqtt = new Workerman\Mqtt\Client("mqtt://test.mosquitto.org:1883");
            $mqtt->onConnect = function($mqtt) {
                $mqtt->subscribe("hello");
            };
            $mqtt->onMessage = function($topic, $content){
                var_dump($topic, $content);
            };
            $mqtt->connect();
        };
        Worker::runAll();
    }
}

=======================================================

:

the above startup is combined with the startup mode of the CI framework. How to add parameters to achieve the following effects similar to starting workerman directly

php start.php start -d

=
question 3
Communication between CI and workerman besides using queues, is there any other method that can actively call or trigger workerman response in CI (the question here is not the communication between workerman and the client)

Jun.29,2021

found a method STDIN constant to determine whether to call CLI to write to the configuration file

.
if (defined('STDIN'))
{
   //hardcode the base url for cli
   $config['base_url'] = "http://yoursite.com/";
}
else
{
   $config['base_url'] = "http".((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "s" : "")."://".$_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
} 

second question, after reading the source code of Worker.php, I wrote a controller to force myself to change the passed parameters

class Mqtt extends CI_Controller {

    public function index($argv=array())
    {
        $worker = new Worker();
        $worker->onWorkerStart = function(){
            $mqtt = new Workerman\Mqtt\Client('mqtt://test.mosquitto.org:1883');
            $mqtt->onConnect = function($mqtt) {
                $mqtt->subscribe('hello');
            };
            $mqtt->onMessage = function($topic, $content){
                var_dump($topic, $content);
            };
            $mqtt->connect();
        };
        Worker::runAll();
    }

    public function start($mode='')
    {
        global $argv;
        $argv[1] = 'start';
        $argv[2] = $mode;
        $this->index($argv);
    }

    public function stop($mode='')
    {
        global $argv;
        $argv[1] = 'stop';
        $argv[2] = $mode;
        $this->index($argv);
    }

    public function restart($mode='')
    {
        global $argv;
        $argv[1] = 'restart';
        $argv[2] = $mode;
        $this->index($argv);
    }

    public function reload($mode='')
    {
        global $argv;
        $argv[1] = 'reload';
        $argv[2] = $mode;
        $this->index($argv);
    }

    public function status($mode='')
    {
        global $argv;
        $argv[1] = 'status';
        $argv[2] = $mode;
        $this->index($argv);
    }

    public function connections($mode='')
    {
        global $argv;
        $argv[1] = 'connections';
        $argv[2] = $mode;
        $this->index($argv);
    }


first question: to determine whether it is a CLI environment, there are two ways:
(1) use PHP built-in functions: php_sapi_name ()
(2) use PHP built-in constants: PHP_SAPI
second question: the workerman framework itself does not support this kind of parameter, unless you modify the kernel code, of course, this is not recommended. So you can only expand the encapsulation layer on the outside. I see your mapping code has achieved a similar effect, that's what it means.


works. Thanks for sharing and solving my problem

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bf3dbb-3162a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bf3dbb-3162a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?