我在網(wǎng)上看見這種自定義的方法
protected function configure()
{
$this->setName('mobile')
->addArgument('action', Argument::OPTIONAL, "action start|stop|restart")
->addArgument('type', Argument::OPTIONAL, "d -d")
->setDescription('mobile');
}
protected function execute(Input $input, Output $output)
{
global $argv;
$action = trim($input->getArgument('action'));
$type = trim($input->getArgument('type')) ? '-d' : '';
$argv[0] = 'mobile';
$argv[1] = $action;
$argv[2] = $type ? '-d' : '';
$output->writeln("Hello," . $action . '!' . $type);
$this->start();
}
然后運(yùn)行php think mobile start d這樣沒問題的
但我在創(chuàng)建一個(gè)命令名稱不一樣 Workerman業(yè)務(wù)也不一樣的新的文件 上面mobile改成app
我運(yùn)行php think app start 會(huì)顯示正在運(yùn)行 執(zhí)行status顯示的是mobile的運(yùn)行狀態(tài)。。導(dǎo)致我啟動(dòng)不了app的這個(gè)Workerman業(yè)務(wù) 請教一下這個(gè)是為什么 要如何修改
thinkphp 官方出了workerman擴(kuò)展,可以試下
https://www.kancloud.cn/manual/thinkphp5/235128 tp5
https://www.kancloud.cn/manual/thinkphp6_0/1147857 tp6
據(jù)我所知,thinkphp官方對workerman的整合存在一些瑕疵,瑕疵的表現(xiàn)之一正如題主描述那樣。
可以說workerman常編寫的這個(gè)啟動(dòng)腳本就等同于thinkphp的一個(gè)個(gè)單獨(dú)的命令類,所以說按照thinkphp的整合邏輯,如果想要一個(gè)個(gè)獨(dú)立的啟動(dòng)腳本,那只能編寫一個(gè)個(gè)獨(dú)立的命令入口類(否則啊你永遠(yuǎn)只能玩一個(gè)啟動(dòng)腳本),即使如此也還需要進(jìn)行一些特別的設(shè)置。
問題原因
單純的更改一個(gè)命令的名字是不行的哈,關(guān)鍵是pidFile,因?yàn)檫\(yùn)行時(shí)pidFile多個(gè)命令類共享的是同一個(gè)。
解決方案
每個(gè)命令類都有一個(gè)對應(yīng)的配置文件,然后在各自的配置文件中分別定義不同的$pidFile,然后還要顯示的設(shè)定一下
Worker::$pidFile = $your_unique_pid_file;(為什么還要設(shè)定一下,因?yàn)閠hinkphp默認(rèn)讀配置時(shí)會(huì)自動(dòng)設(shè)置,但是一旦你設(shè)置了自定義類,它就不管了,所以......)