@@ -1193,6 +1193,45 @@ static nr_status_t nr_laravel_should_assign_generic_path(const nrtxn_t* txn,
11931193 return NR_FAILURE ;
11941194}
11951195
1196+ /*
1197+ * Ensure that the transaction is properly stopped when Laravel Horizon is being
1198+ * used by wrapping the handle method of the HorizonCommand and
1199+ * SupervisorCommand class.
1200+ */
1201+ NR_PHP_WRAPPER (nr_laravel_horizon_end_txn ) {
1202+ NR_UNUSED_SPECIALFN ;
1203+ (void )wraprec ;
1204+
1205+ nr_php_txn_end (1 , 0 TSRMLS_CC );
1206+
1207+ nrl_verbosedebug (NRL_FRAMEWORK , "Ending Laravel Horizon Transaction" );
1208+ }
1209+ NR_PHP_WRAPPER_END
1210+
1211+ /*
1212+ * End transaction for idle laravel queue workers and then start
1213+ * a new transaction.
1214+ */
1215+ NR_PHP_WRAPPER (nr_laravel_queue_restart_transaction ) {
1216+ NR_UNUSED_SPECIALFN ;
1217+ (void )wraprec ;
1218+
1219+ nr_php_txn_end (1 , 0 TSRMLS_CC );
1220+ nr_php_txn_begin (NULL , NULL TSRMLS_CC );
1221+ }
1222+ NR_PHP_WRAPPER_END
1223+
1224+ /*
1225+ * Set global flag that checks if Laravel Horizon is being used to true.
1226+ */
1227+ NR_PHP_WRAPPER (nr_laravel_horizon_is_used ) {
1228+ NR_UNUSED_SPECIALFN ;
1229+ (void )wraprec ;
1230+
1231+ NR_PHP_PROCESS_GLOBALS (laravel_horizon_worker_used ) = true;
1232+ }
1233+ NR_PHP_WRAPPER_END
1234+
11961235void nr_laravel_enable (TSRMLS_D ) {
11971236 /*
11981237 * We set the path to 'unknown' to prevent having to name routing errors.
@@ -1231,6 +1270,33 @@ void nr_laravel_enable(TSRMLS_D) {
12311270 nr_php_wrap_user_function_before_after_clean (
12321271 NR_PSTR ("Symfony\\Component\\Console\\Application::doRun" ),
12331272 nr_laravel_console_application_dorun , NULL , NULL );
1273+
1274+ /*
1275+ * The following functions have been added to ensure that the transaction
1276+ * is properly stopped when Laravel Horizon is being used. This is
1277+ * accomplished by wrapping the handle method of the HorizonCommand class and
1278+ * the SupervisorCommand class.
1279+ */
1280+ nr_php_wrap_user_function_before_after_clean (
1281+ NR_PSTR ("Laravel\\Horizon\\Console\\HorizonCommand::handle" ),
1282+ nr_laravel_horizon_end_txn , NULL , NULL );
1283+ nr_php_wrap_user_function_before_after_clean (
1284+ NR_PSTR ("Laravel\\Horizon\\Console\\SupervisorCommand::handle" ),
1285+ nr_laravel_horizon_end_txn , NULL , NULL );
1286+ /*
1287+ * Check if Laravel Horizon is being used.
1288+ */
1289+ nr_php_wrap_user_function_before_after_clean (
1290+ NR_PSTR ("Laravel\\Horizon\\Console\\WorkCommand::handle" ),
1291+ nr_laravel_horizon_is_used , NULL , NULL );
1292+ /*
1293+ * The following function has been added to ensure idle laravel queue workers
1294+ * are properly handled by ending the current transaction and starting a new
1295+ * one.
1296+ */
1297+ nr_php_wrap_user_function_before_after_clean (
1298+ NR_PSTR ("Illuminate\\Queue\\Worker::daemonShouldRun" ),
1299+ nr_laravel_queue_restart_transaction , NULL , NULL );
12341300#else
12351301 nr_php_wrap_user_function (NR_PSTR ("Symfony\\Component\\Console\\Application::doRun" ),
12361302 nr_laravel_console_application_dorun TSRMLS_CC );
0 commit comments