View Issue Details

IDProjectCategoryView StatusLast Update
0037018mantisbtperformancepublic2026-04-18 05:33
Reporterraspopov Assigned Todregad  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Product Version2.28.1 
Target Version2.29.0Fixed in Version2.29.0 
Summary0037018: The require_once() function is called more times than necessary when loading the API.
Description

While investigating issue 0036819, I discovered that the require_api() function calls require_once() more often than necessary, and even recursively.

For example, 63 files are loaded from the API via 88 calls for the file my_view_page.php, even though there should obviously only be 63. This process involves 716 calls to the require_api() function.

Additional Information

The table below lists the API file calls in the order that the require_once() calls are completed, along with the number of calls:

                   php_api.php |  4 ####
              constant_inc.php | 62 ##############################################################
        authentication_api.php | 29 #############################
                access_api.php | 33 #################################
                   bug_api.php | 26 ##########################
                config_api.php | 55 #######################################################
              compress_api.php |  3 ###
              database_api.php | 33 #################################
          current_user_api.php | 21 #####################
                 error_api.php | 29 #############################
                  http_api.php |  2 ##
                   gpc_api.php | 12 ############
                tokens_api.php |  3 ###
               utility_api.php | 34 ##################################
              collapse_api.php |  5 #####
                  html_api.php |  9 #########
                events_inc.php |  1 #
                plugin_api.php |  4 ####
                 event_api.php | 10 ##########
              antispam_api.php |  4 ####
                helper_api.php | 38 ######################################
               history_api.php | 12 ############
              category_api.php | 13 #############
          bug_revision_api.php |  3 ###
                 email_api.php |  8 ########
                  file_api.php | 13 #############
                  lang_api.php | 35 ###################################
               mention_api.php |  3 ###
                filter_api.php | 11 ###########
               logging_api.php |  8 ########
                  user_api.php | 24 ########################
                  ldap_api.php |  2 ##
               project_api.php | 22 ######################
     project_hierarchy_api.php |  5 #####
               bugnote_api.php |  6 ######
                string_api.php | 23 #######################
             user_pref_api.php |  8 ########
          custom_field_api.php |  9 #########
           email_queue_api.php |  2 ##
                crypto_api.php |  5 #####
               session_api.php |  3 ###
                  form_api.php |  4 ####
                  date_api.php |  4 ####
               version_api.php |  5 #####
               prepare_api.php |  4 ####
      bug_group_action_api.php |  1 #
          last_visited_api.php |  1 #
                  news_api.php |  3 ###
               profile_api.php |  2 ##
                   tag_api.php |  4 ####
                 print_api.php | 16 ################
          relationship_api.php |  5 #####
           sponsorship_api.php |  4 ####
               columns_api.php |  4 ####
                  icon_api.php |  8 ########
      filter_constants_inc.php | 11 ###########
           filter_form_api.php |  1 #
                   rss_api.php |  1 #
                layout_api.php |  2 ##
             api_token_api.php |  1 #
               summary_api.php |  1 #
       custom_function_api.php |  1 #
              timeline_api.php |  1 #
TagsNo tags attached.

Relationships

related to 0036819 resolveddregad Secure cookies are rejected by the browser 

Activities

raspopov

raspopov

2026-04-12 09:27

reporter   ~0070973

PR: https://github.com/mantisbt/mantisbt/pull/2207

dregad

dregad

2026-04-12 10:34

developer   ~0070974

The high number of require_api() calls is not so surprising, considering the complex inter-dependencies between the various API files in the MantisBT core. Most files are included by core.php, and requiring API files again in individual scripts is often redundant.

require_api() was introduced by @dhx in 2010, see MantisBT master 2d5455cc, replacing earlier use of require_once in core.php (MantisBT master ea3cd389). The purpose of these changes was to

  • load the most important APIs as part of core
  • avoid having to worry about indirect dependencies (e.g. I want to use gpc_api.php, so I need to include constant_inc.php and error_api.php first).
  • optimize for performance - require_once execution was costlier than checking for an array key. From the commit message:

    require_api and require_lib use a global array to keep track of which
    files have already been included. This is a much simpler check than what
    is performed by require_once and hence avoids expensive checking for
    symlinks with stat() calls and so forth.

That being said, I'm not really sure why he set the flag in the array after the require_once call, maybe the idea was to indicate that the API was fully loaded and available..

In any case, the proposed change goes along the initial intent, so I think it's good, assuming you have tested that changing this does not introduce any regression.

raspopov

raspopov

2026-04-12 12:26

reporter   ~0070975

That being said, I'm not really sure why he set the flag in the array after the require_once call, maybe the idea was to indicate that the API was fully loaded and available..

The current use of the flag opens the door to recursive calls, and the flag may be set to 1 multiple times (repeatedly). Furthermore, it is not checked anywhere else except at this point...

Related Changesets

MantisBT: master 87fdaa05

2026-04-12 09:24

raspopov

Committer: dregad


Details Diff
Fix extra require_once() calls from require_api()

To prevent recursive calls to the require_api() function, move
the loading flag after require_once() to before it.

Fixes 0037018.
Affected Issues
0037018
mod - core.php Diff File

MantisBT: master 34bbf8f5

2026-04-15 11:05

raspopov

Committer: dregad


Details Diff
Fix require_lib() in the same way

Also arrays has been formatted.

Fixes 0037018
Affected Issues
0037018
mod - core.php Diff File