File tree Expand file tree Collapse file tree 3 files changed +67
-37
lines changed Expand file tree Collapse file tree 3 files changed +67
-37
lines changed Original file line number Diff line number Diff line change @@ -113,4 +113,71 @@ public function aliveCount()
113113
114114 return $ count ;
115115 }
116+
117+ /**
118+ * get process by name
119+ *
120+ * @param string $name process name
121+ * @return Process|null
122+ */
123+ public function getProcessByName ($ name )
124+ {
125+ foreach ($ this ->processes as $ process ) {
126+ if ($ process ->name () == $ name ) {
127+ return $ process ;
128+ }
129+ }
130+
131+ return null ;
132+ }
133+
134+ /**
135+ * remove process by name
136+ *
137+ * @param string $name process name
138+ * @throws \RuntimeException
139+ */
140+ public function removeProcessByName ($ name )
141+ {
142+ foreach ($ this ->processes as $ key => $ process ) {
143+ if ($ process ->name () == $ name ) {
144+ if ($ process ->isRunning ()) {
145+ throw new \RuntimeException ("can not remove a running process " );
146+ }
147+ unset($ this ->processes [$ key ]);
148+ }
149+ }
150+ }
151+
152+ /**
153+ * remove exited process
154+ */
155+ public function removeExitedProcess ()
156+ {
157+ foreach ($ this ->processes as $ key => $ process ) {
158+ if ($ process ->isStopped ()) {
159+ unset($ this ->processes [$ key ]);
160+ }
161+ }
162+ }
163+
164+ /**
165+ * return process count
166+ *
167+ * @return int
168+ */
169+ public function count ()
170+ {
171+ return count ($ this ->processes );
172+ }
173+
174+ /**
175+ * get all processes
176+ *
177+ * @return Process[]
178+ */
179+ public function getProcesses ()
180+ {
181+ return $ this ->processes ;
182+ }
116183}
Original file line number Diff line number Diff line change @@ -103,24 +103,4 @@ public function start()
103103 }
104104 }
105105 }
106-
107- /**
108- * return process count
109- *
110- * @return int
111- */
112- public function count ()
113- {
114- return count ($ this ->processes );
115- }
116-
117- /**
118- * get all processes
119- *
120- * @return Process[]
121- */
122- public function getProcesses ()
123- {
124- return $ this ->processes ;
125- }
126106}
Original file line number Diff line number Diff line change @@ -35,21 +35,4 @@ public function execute(Process $process, $name = null)
3535
3636 return array_push ($ this ->processes , $ process );
3737 }
38-
39- /**
40- * get process by name
41- *
42- * @param string $name process name
43- * @return Process|null
44- */
45- public function getProcessByName ($ name )
46- {
47- foreach ($ this ->processes as $ process ) {
48- if ($ process ->name () == $ name ) {
49- return $ process ;
50- }
51- }
52-
53- return null ;
54- }
5538}
You can’t perform that action at this time.
0 commit comments