File tree Expand file tree Collapse file tree 4 files changed +46
-0
lines changed Expand file tree Collapse file tree 4 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,12 @@ public static function get()
41
41
});
42
42
43
43
register_shutdown_function (function () use ($ loop , &$ hasRun ) {
44
+ // Don't run if we're coming from a fatal error (uncaught exception).
45
+ $ error = error_get_last ();
46
+ if ((isset ($ error ['type ' ]) ? $ error ['type ' ] : 0 ) & (E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR )) {
47
+ return ;
48
+ }
49
+
44
50
if (!$ hasRun ) {
45
51
$ loop ->run ();
46
52
}
Original file line number Diff line number Diff line change @@ -36,4 +36,22 @@ public function testExecuteExampleWithExplicitLoopRunAndStopRunsLoopAndExecutesT
36
36
37
37
$ this ->assertEquals ('abc ' , $ output );
38
38
}
39
+
40
+ public function testExecuteExampleWithUncaughtExceptionShouldNotRunLoop ()
41
+ {
42
+ $ time = microtime (true );
43
+ exec (escapeshellarg (PHP_BINARY ) . ' 11-uncaught.php 2>/dev/null ' );
44
+ $ time = microtime (true ) - $ time ;
45
+
46
+ $ this ->assertLessThan (1.0 , $ time );
47
+ }
48
+
49
+ public function testExecuteExampleWithUndefinedVariableShouldNotRunLoop ()
50
+ {
51
+ $ time = microtime (true );
52
+ exec (escapeshellarg (PHP_BINARY ) . ' 12-undefined.php 2>/dev/null ' );
53
+ $ time = microtime (true ) - $ time ;
54
+
55
+ $ this ->assertLessThan (1.0 , $ time );
56
+ }
39
57
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use React \EventLoop \Loop ;
4
+
5
+ require __DIR__ . '/../../vendor/autoload.php ' ;
6
+
7
+ Loop::addTimer (10.0 , function () {
8
+ echo 'never ' ;
9
+ });
10
+
11
+ throw new RuntimeException ();
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use React \EventLoop \Loop ;
4
+
5
+ require __DIR__ . '/../../vendor/autoload.php ' ;
6
+
7
+ Loop::get ()->addTimer (10.0 , function () {
8
+ echo 'never ' ;
9
+ });
10
+
11
+ $ undefined ->foo ('bar ' );
You can’t perform that action at this time.
0 commit comments