diff --git a/agent/fw_laravel.c b/agent/fw_laravel.c index 1d0b25794..c3a42ffea 100644 --- a/agent/fw_laravel.c +++ b/agent/fw_laravel.c @@ -1208,6 +1208,19 @@ NR_PHP_WRAPPER(nr_laravel_horizon_end_txn) { } NR_PHP_WRAPPER_END +/* + * End transaction for idle laravel queue workers and then start + * a new transaction. + */ +NR_PHP_WRAPPER(nr_laravel_queue_restart_transaction) { + NR_UNUSED_SPECIALFN; + (void)wraprec; + + nr_php_txn_end(1, 0 TSRMLS_CC); + nr_php_txn_begin(NULL, NULL TSRMLS_CC); +} +NR_PHP_WRAPPER_END + void nr_laravel_enable(TSRMLS_D) { /* * We set the path to 'unknown' to prevent having to name routing errors. @@ -1259,6 +1272,15 @@ void nr_laravel_enable(TSRMLS_D) { nr_php_wrap_user_function_before_after_clean( NR_PSTR("Laravel\\Horizon\\Console\\SupervisorCommand::handle"), nr_laravel_horizon_end_txn, NULL, NULL); + + /* + * The following function has been added to ensure idle laravel queue workers + * are properly handled by ending the current transaction and starting a new + * one. + */ + nr_php_wrap_user_function_before_after_clean( + NR_PSTR("Illuminate\\Queue\\Worker::daemonShouldRun"), + nr_laravel_queue_restart_transaction, NULL, NULL); #else nr_php_wrap_user_function(NR_PSTR("Symfony\\Component\\Console\\Application::doRun"), nr_laravel_console_application_dorun TSRMLS_CC);