@@ -49,7 +49,7 @@ public static function fork(callable $onStart = null, callable $onError = null,
4949 'startTime ' => \time (),
5050 ];
5151 } elseif ($ pid === 0 ) { // at child
52- $ pid = \getmypid ();
52+ $ pid = self :: getPid ();
5353
5454 if ($ onStart ) {
5555 $ onStart ($ pid , $ id );
@@ -419,7 +419,7 @@ public static function dispatchSignal(): bool
419419 return false ;
420420 }
421421
422- // receive and dispatch sig
422+ // receive and dispatch signal
423423 return \pcntl_signal_dispatch ();
424424 }
425425
@@ -434,6 +434,19 @@ public static function getSignalHandler(int $signal)
434434 return \pcntl_signal_get_handler ($ signal );
435435 }
436436
437+ /**
438+ * Enable/disable asynchronous signal handling or return the old setting
439+ * @param bool|null $on
440+ * - bool Enable or disable.
441+ * - null Return old setting.
442+ * @return bool
443+ * @since 7.1
444+ */
445+ public static function asyncSignal (bool $ on = null ): bool
446+ {
447+ return \pcntl_async_signals ($ on );
448+ }
449+
437450 /**************************************************************************************
438451 * some help method
439452 *************************************************************************************/
@@ -445,29 +458,29 @@ public static function getSignalHandler(int $signal)
445458 public static function getPid (): int
446459 {
447460 if (\function_exists ('posix_getpid ' )) {
448- return posix_getpid ();
461+ return \ posix_getpid ();
449462 }
450463
451- return \getmypid ();// or use posix_getpid()
464+ return \getmypid ();
452465 }
453466
454467 /**
455- * get Pid from File
468+ * get PID by pid File
456469 * @param string $file
457470 * @param bool $checkLive
458471 * @return int
459472 */
460- public static function getPidByFile (string $ file , $ checkLive = false ): int
473+ public static function getPidByFile (string $ file , bool $ checkLive = false ): int
461474 {
462- if ($ file && file_exists ($ file )) {
463- $ pid = (int )file_get_contents ($ file );
475+ if ($ file && \ file_exists ($ file )) {
476+ $ pid = (int )\ file_get_contents ($ file );
464477
465478 // check live
466479 if ($ checkLive && self ::isRunning ($ pid )) {
467480 return $ pid ;
468481 }
469482
470- unlink ($ file );
483+ \ unlink ($ file );
471484 }
472485
473486 return 0 ;
@@ -553,7 +566,7 @@ public static function setTitle(string $title): bool
553566 return \cli_set_process_title ($ title );
554567 }
555568
556- return true ;
569+ return false ;
557570 }
558571
559572 /**
@@ -564,7 +577,7 @@ public static function setTitle(string $title): bool
564577 */
565578 public static function changeScriptOwner (string $ user , string $ group = '' )
566579 {
567- $ uInfo = posix_getpwnam ($ user );
580+ $ uInfo = \ posix_getpwnam ($ user );
568581
569582 if (!$ uInfo || !isset ($ uInfo ['uid ' ])) {
570583 throw new \RuntimeException ("User ( {$ user }) not found. " );
@@ -589,13 +602,13 @@ public static function changeScriptOwner(string $user, string $group = '')
589602
590603 \posix_setgid ($ gid );
591604
592- if (posix_geteuid () !== $ gid ) {
605+ if (\ posix_geteuid () !== $ gid ) {
593606 throw new \RuntimeException ("Unable to change group to {$ user } (UID: {$ gid }). " , -300 );
594607 }
595608
596609 \posix_setuid ($ uid );
597610
598- if (posix_geteuid () !== $ uid ) {
611+ if (\ posix_geteuid () !== $ uid ) {
599612 throw new \RuntimeException ("Unable to change user to {$ user } (UID: {$ uid }). " , -300 );
600613 }
601614 }
0 commit comments