@@ -13,8 +13,11 @@ final class Timeout
1313 /** @var bool */
1414 private static $ initialized = false ;
1515
16- /** @var string|null */
17- private static $ stackTrace = null ;
16+ /**
17+ * @var bool
18+ * @internal
19+ */
20+ public static $ _tiggered = false ;
1821
1922 /**
2023 * @internal
@@ -44,8 +47,6 @@ public static function enable(int $remainingTimeInMillis): void
4447 */
4548 private static function init (): void
4649 {
47- self ::$ stackTrace = null ;
48-
4950 if (self ::$ initialized ) {
5051 return ;
5152 }
@@ -60,25 +61,16 @@ private static function init(): void
6061 // Setup a handler for SIGALRM that throws an exception
6162 // This will interrupt any running PHP code, including `sleep()` or code stuck waiting for I/O.
6263 pcntl_signal (SIGALRM , function (): void {
63- if (null !== Timeout::$ stackTrace ) {
64- // we have already thrown an exception, do a harder exit.
65- error_log ('Lambda timed out ' );
66- error_log ((new LambdaTimeoutException ())->getTraceAsString ());
67- error_log ('Original stack trace ' );
68- error_log (Timeout::$ stackTrace );
69-
70- exit (1 );
71- }
72-
64+ Timeout::$ _tiggered = true ;
7365 $ exception = new LambdaTimeoutException ('Maximum AWS Lambda execution time reached ' );
74- Timeout::$ stackTrace = $ exception ->getTraceAsString ();
75-
76- // Trigger another alarm after 1 second to do a hard exit.
77- pcntl_alarm (1 );
66+ // we have already thrown an exception, do a harder exit.
67+ error_log ($ exception ->getMessage ());
68+ error_log ($ exception ->getTraceAsString ());
7869
79- throw $ exception ;
70+ exit ( 1 ) ;
8071 });
8172
73+ self ::$ _tiggered = false ;
8274 self ::$ initialized = true ;
8375 }
8476
@@ -91,7 +83,6 @@ public static function reset(): void
9183 {
9284 if (self ::$ initialized ) {
9385 pcntl_alarm (0 );
94- self ::$ stackTrace = null ;
9586 }
9687 }
9788}
0 commit comments