@@ -16,10 +16,12 @@ class ServerCommand
1616 /**
1717 * Start http server
1818 *
19- * @Usage server:{command } [arguments] [options ]
19+ * @Usage {fullCommand } [-d|--daemon ]
2020 * @Options
21- * -d,--d start by daemonized process
22- * @Example php swoft.php server:start -d -r
21+ * -d, --daemon Run server on the background
22+ * @Example
23+ * {fullCommand}
24+ * {fullCommand} -d
2325 * @throws \Swoft\Exception\RuntimeException
2426 * @throws \RuntimeException
2527 */
@@ -32,7 +34,7 @@ public function start()
3234
3335 // 是否正在运行
3436 if ($ httpServer ->isRunning ()) {
35- output ()->writeln ("<error>The server have been running!(PID: {$ serverStatus ['masterPid ' ]})</error> " , true , true );
37+ \ output ()->writeln ("<error>The server have been running!(PID: {$ serverStatus ['masterPid ' ]})</error> " , true , true );
3638 }
3739
3840 // 启动参数
@@ -54,29 +56,30 @@ public function start()
5456 $ tcpHost = $ tcpStatus ['host ' ];
5557 $ tcpPort = $ tcpStatus ['port ' ];
5658 $ tcpType = $ tcpStatus ['type ' ];
57- $ tcpEnable = $ tcpEnable ? 1 : 0 ;
59+ $ tcpEnable = $ tcpEnable ? ' <note>Enabled</note> ' : ' <warning>Disabled</warning> ' ;
5860
5961 // 信息面板
6062 $ lines = [
61- ' Information Panel ' ,
62- '****************************************************************** ' ,
63- "* http | Host : <note> $ httpHost</note>, port: <note> $ httpPort</note>, Model : <note> $ httpMode </note>, type : <note> $ httpType </note>, Worker : <note> $ workerNum </note> " ,
64- "* tcp | Enable: <note> $ tcpEnable </note>, host: <note>$ tcpHost</note>, port: <note> $ tcpPort</note>, type: <note> $ tcpType</note>, Worker : <note> $ workerNum</note> " ,
65- '****************************************************************** ' ,
63+ ' Server Information ' ,
64+ '******************************************************************** ' ,
65+ "* HTTP | host : <note> $ httpHost</note>, port: <note> $ httpPort</note>, type : <note> $ httpType </note>, worker : <note> $ workerNum </note>, mode : <note> $ httpMode </note> " ,
66+ "* TCP | host: <note> $ tcpHost</note>, port: <note> $ tcpPort</note>, type: <note> $ tcpType</note>, worker : <note> $ workerNum</note> ( $ tcpEnable ) " ,
67+ '******************************************************************** ' ,
6668 ];
6769
6870 // 启动服务器
69- output ()->writeln (implode ("\n" , $ lines ));
71+ \ output ()->writeln (implode ("\n" , $ lines ));
7072 $ httpServer ->start ();
7173 }
7274
7375 /**
74- * Reload worker process
76+ * Reload worker processes
7577 *
76- * @Usage server:{command } [arguments] [options ]
78+ * @Usage {fullCommand } [-t ]
7779 * @Options
78- * -t only to reload task processes, default to reload worker and task
79- * @Example php swoft.php server:reload
80+ * -t Only to reload task processes, default to reload worker and task
81+ * @Example {fullCommand}
82+ * @throws \InvalidArgumentException
8083 * @throws \RuntimeException
8184 */
8285 public function reload ()
@@ -97,10 +100,10 @@ public function reload()
97100 }
98101
99102 /**
100- * Stop http server
103+ * Stop the http server
101104 *
102- * @Usage server:{command} [arguments] [options]
103- * @Example php swoft.php server:stop
105+ * @Usage {fullCommand}
106+ * @Example {fullCommand}
104107 * @throws \RuntimeException
105108 */
106109 public function stop ()
@@ -109,31 +112,36 @@ public function stop()
109112
110113 // 是否已启动
111114 if (!$ httpServer ->isRunning ()) {
112- output ()->writeln ('<error>The server is not running! cannot stop</error> ' , true , true );
115+ \ output ()->writeln ('<error>The server is not running! cannot stop</error> ' , true , true );
113116 }
114117
115118 // pid文件
116119 $ serverStatus = $ httpServer ->getServerSetting ();
117120 $ pidFile = $ serverStatus ['pfile ' ];
118121
119122 @unlink ($ pidFile );
120- output ()->writeln (sprintf ('<info>Swoft %s is stopping ...</info> ' , input ()->getScript ()));
123+ \ output ()->writeln (sprintf ('<info>Swoft %s is stopping ...</info> ' , input ()->getScript ()));
121124
122125 $ result = $ httpServer ->stop ();
123126
124127 // 停止失败
125128 if (!$ result ) {
126- output ()->writeln (sprintf ('<error>Swoft %s stop fail</error> ' , input ()->getScript ()), true , true );
129+ \ output ()->writeln (sprintf ('<error>Swoft %s stop fail</error> ' , input ()->getScript ()), true , true );
127130 }
128131
129132 output ()->writeln (sprintf ('<success>Swoft %s stop success!</success> ' , input ()->getScript ()));
130133 }
131134
132135 /**
133- * Restart http server
136+ * Restart the http server
134137 *
135- * @Usage server:{command} [arguments] [options]
136- * @Example php swoft.php server:restart
138+ * @Usage {fullCommand} [-d|--daemon]
139+ * @Options
140+ * -d, --daemon Run server on the background
141+ * @Example
142+ * {fullCommand}
143+ * {fullCommand} -d
144+ * @throws \InvalidArgumentException
137145 * @throws \RuntimeException
138146 */
139147 public function restart ()
@@ -152,6 +160,7 @@ public function restart()
152160
153161 /**
154162 * @return HttpServer
163+ * @throws \InvalidArgumentException
155164 * @throws \RuntimeException
156165 */
157166 private function getHttpServer (): HttpServer
@@ -175,7 +184,7 @@ private function getHttpServer(): HttpServer
175184 */
176185 private function setStartArgs (HttpServer $ httpServer )
177186 {
178- $ daemonize = input ()->hasOpt ( 'd ' );
187+ $ daemonize = \ input ()->getSameOpt ([ 'd ' , ' daemon ' ], false );
179188
180189 if ($ daemonize ) {
181190 $ httpServer ->setDaemonize ();
0 commit comments