@@ -56,8 +56,8 @@ class Process
56
56
private $ enhanceSigchildCompatibility ;
57
57
private $ process ;
58
58
private $ status = self ::STATUS_READY ;
59
- private $ incrementalOutputOffset ;
60
- private $ incrementalErrorOutputOffset ;
59
+ private $ incrementalOutputOffset = 0 ;
60
+ private $ incrementalErrorOutputOffset = 0 ;
61
61
private $ tty ;
62
62
63
63
private $ useFileHandles = false ;
@@ -186,7 +186,8 @@ public function __clone()
186
186
*
187
187
* @return integer The exit status code
188
188
*
189
- * @throws RuntimeException When process can't be launch or is stopped
189
+ * @throws RuntimeException When process can't be launched
190
+ * @throws RuntimeException When process stopped after receiving signal
190
191
*
191
192
* @api
192
193
*/
@@ -215,7 +216,7 @@ public function run($callback = null)
215
216
* @param callback|null $callback A PHP callback to run whenever there is some
216
217
* output available on STDOUT or STDERR
217
218
*
218
- * @throws RuntimeException When process can't be launch or is stopped
219
+ * @throws RuntimeException When process can't be launched
219
220
* @throws RuntimeException When process is already running
220
221
*/
221
222
public function start ($ callback = null )
@@ -270,7 +271,7 @@ public function start($callback = null)
270
271
*
271
272
* @return Process The new process
272
273
*
273
- * @throws RuntimeException When process can't be launch or is stopped
274
+ * @throws RuntimeException When process can't be launched
274
275
* @throws RuntimeException When process is already running
275
276
*
276
277
* @see start()
@@ -355,6 +356,7 @@ public function getPid()
355
356
* Sends a POSIX signal to the process.
356
357
*
357
358
* @param integer $signal A valid POSIX signal (see http://www.php.net/manual/en/pcntl.constants.php)
359
+ *
358
360
* @return Process
359
361
*
360
362
* @throws LogicException In case the process is not running
@@ -511,7 +513,7 @@ public function isSuccessful()
511
513
* @return Boolean
512
514
*
513
515
* @throws RuntimeException In case --enable-sigchild is activated
514
- * @throws LogicException In case the process is not terminated.
516
+ * @throws LogicException In case the process is not terminated
515
517
*
516
518
* @api
517
519
*/
@@ -536,7 +538,7 @@ public function hasBeenSignaled()
536
538
* @return integer
537
539
*
538
540
* @throws RuntimeException In case --enable-sigchild is activated
539
- * @throws LogicException In case the process is not terminated.
541
+ * @throws LogicException In case the process is not terminated
540
542
*
541
543
* @api
542
544
*/
@@ -560,7 +562,7 @@ public function getTermSignal()
560
562
*
561
563
* @return Boolean
562
564
*
563
- * @throws LogicException In case the process is not terminated.
565
+ * @throws LogicException In case the process is not terminated
564
566
*
565
567
* @api
566
568
*/
@@ -580,7 +582,7 @@ public function hasBeenStopped()
580
582
*
581
583
* @return integer
582
584
*
583
- * @throws LogicException In case the process is not terminated.
585
+ * @throws LogicException In case the process is not terminated
584
586
*
585
587
* @api
586
588
*/
@@ -686,8 +688,6 @@ public function stop($timeout = 10, $signal = null)
686
688
$ this ->close ();
687
689
}
688
690
689
- $ this ->status = self ::STATUS_TERMINATED ;
690
-
691
691
return $ this ->exitcode ;
692
692
}
693
693
@@ -1039,7 +1039,7 @@ protected function buildCallback($callback)
1039
1039
/**
1040
1040
* Updates the status of the process, reads pipes.
1041
1041
*
1042
- * @param Boolean $blocking Whether to use a clocking read call.
1042
+ * @param Boolean $blocking Whether to use a blocking read call.
1043
1043
*/
1044
1044
protected function updateStatus ($ blocking )
1045
1045
{
@@ -1054,7 +1054,6 @@ protected function updateStatus($blocking)
1054
1054
1055
1055
if (!$ this ->processInformation ['running ' ]) {
1056
1056
$ this ->close ();
1057
- $ this ->status = self ::STATUS_TERMINATED ;
1058
1057
}
1059
1058
}
1060
1059
@@ -1119,17 +1118,17 @@ private function captureExitCode()
1119
1118
*/
1120
1119
private function close ()
1121
1120
{
1122
- $ exitcode = -1 ;
1123
-
1124
1121
$ this ->processPipes ->close ();
1125
1122
if (is_resource ($ this ->process )) {
1126
1123
$ exitcode = proc_close ($ this ->process );
1124
+ } else {
1125
+ $ exitcode = -1 ;
1127
1126
}
1128
1127
1129
- $ this ->exitcode = $ this -> exitcode !== null ? $ this ->exitcode : -1 ;
1130
- $ this ->exitcode = - 1 != $ exitcode ? $ exitcode : $ this -> exitcode ;
1128
+ $ this ->exitcode = - 1 !== $ exitcode ? $ exitcode : ( null !== $ this -> exitcode ? $ this ->exitcode : -1 ) ;
1129
+ $ this ->status = self :: STATUS_TERMINATED ;
1131
1130
1132
- if (-1 == $ this ->exitcode && null !== $ this ->fallbackExitcode ) {
1131
+ if (-1 === $ this ->exitcode && null !== $ this ->fallbackExitcode ) {
1133
1132
$ this ->exitcode = $ this ->fallbackExitcode ;
1134
1133
} elseif (-1 === $ this ->exitcode && $ this ->processInformation ['signaled ' ] && 0 < $ this ->processInformation ['termsig ' ]) {
1135
1134
// if process has been signaled, no exitcode but a valid termsig, apply Unix convention
@@ -1161,7 +1160,8 @@ private function resetProcessData()
1161
1160
* Sends a POSIX signal to the process.
1162
1161
*
1163
1162
* @param integer $signal A valid POSIX signal (see http://www.php.net/manual/en/pcntl.constants.php)
1164
- * @param Boolean $throwException True to throw exception in case signal failed, false otherwise
1163
+ * @param Boolean $throwException Whether to throw exception in case signal failed
1164
+ *
1165
1165
* @return Boolean True if the signal was sent successfully, false otherwise
1166
1166
*
1167
1167
* @throws LogicException In case the process is not running
0 commit comments