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()
4141 });
4242
4343 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+
4450 if (!$ hasRun ) {
4551 $ loop ->run ();
4652 }
Original file line number Diff line number Diff line change @@ -36,4 +36,22 @@ public function testExecuteExampleWithExplicitLoopRunAndStopRunsLoopAndExecutesT
3636
3737 $ this ->assertEquals ('abc ' , $ output );
3838 }
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+ }
3957}
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