From e19c6cc9f2ffa67d7e93c63de5535b2aa234e983 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Sun, 10 May 2020 19:29:58 +0000 Subject: [PATCH] Fork / TCPServer : manage the background job to catch the errors triggered by PHP git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5981 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- fork.php | 10 ++++++++-- tcpserver.php | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/fork.php b/fork.php index e866c7a..cd1715d 100644 --- a/fork.php +++ b/fork.php @@ -19,8 +19,10 @@ class fork if (! function_exists ("pcntl_fork")) throw new \Exception ("Can't fork as PHP doesn't have the pcntl_fork", 500); - declare (ticks=1); - @pcntl_async_signals (true); + if (function_exists ("pcntl_async_signals")) + pcntl_async_signals (true); + else + declare (ticks=1); } /** Return the number of active PID @@ -89,6 +91,10 @@ class fork // there is an "echo" ob_start (); + // Catch the error messages from the application to not hang if triggered + // An other handler can be set in function to execute + set_error_handler (function () {}); + // Close the file handlers STDOUT/STDIN fclose (STDIN); fclose (STDOUT); diff --git a/tcpserver.php b/tcpserver.php index 994ce5f..098919e 100644 --- a/tcpserver.php +++ b/tcpserver.php @@ -357,6 +357,9 @@ class tcpserver // Will catch all the text messages from the application to not crash if // there is an "echo" ob_start (); + // Catch the error messages from the application to not hang if triggered + // An other handler can be set in function to execute + set_error_handler (function () {}); @fclose (STDIN); @fclose (STDOUT); @fclose (STDERR);