• jmanpa

    (@jmanpa)


    I am seeing add_action code being executed for plugins way more times than I would expect. I modified Hello Dolly below, to demonstrate by simply outputting some text after the basic Hello Dolly functionality is executed. I added only logging (no architectural or logic changes) to show how many executions WordPress core is doing within a plugin script for a single admin page refresh.

    With the Twenty Ten theme and a single refresh of the Dashboard, Hello Dolly’s add_action for the admin_footer runs eight times, and therefore, hello_dolly_get_lyric() runs 8 times though you can see the result only once on the admin page in the upper right.

    Even more surprisingly, both add_action and hello_dolly_get_lyric() run 15 times when displaying the home page – where admin-related actions should not be executing. No lyrics display, so unless you are watching the logging code I put in, one would never know that this is going on on a normal basis.

    I bring this up because if this is all true and I haven’t configured something incorrectly, this is a huge, huge waste of resources.

    I would really appreciate someone could take 2 minutes to test my version of Hello Dolly below and see if you get the same results in your error_log file. In my mind, I should see that code execute once in admin functions per plugin file and never on the blog home page.

    [Large code excerpt removed by moderator per forum rules. Please use the pastebin for all large code excerpts. It works better anyway.]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter jmanpa

    (@jmanpa)

    To be clear, I wasn’t worried about Hello Dolly – it was just a test case that is simple enough to quickly observe the behavior of WordPress and it’s calls to the plugin functions. I’m concerned that all plugins currently active will exhibit this call overload from WordPress.

    Thread Starter jmanpa

    (@jmanpa)

    I tracked down some strange behavior to core (or maybe Apache, don’t know):

    If you have permalinks set to default (?p=123) the loop gets called multiple times, and thus, all the reduntant calls to my plugin add_action described above.

    Any other permalink setting will not exhibit this multiple loop behavior.

    The following error_log entries show 5 tests, each one changing the permalink structure and refreshing the home page. The last 8 lines show a single page refresh with default permalink settings. The loop is executed 8 times.

    Why might this be?

    My test involved adding one line of code to the beginning of loop.php:

    <?php error_log("about to start loop: permalink structure: " . get_option('permalink_structure'),0); ?>
    <?php while ( have_posts() ) : the_post(); ?>
    [10-Nov-2010 14:31:00] about to start loop: permalink structure: /%year%/%monthnum%/%day%/%postname%/
    [10-Nov-2010 14:31:15] about to start loop: permalink structure: /%year%/%monthnum%/%postname%/
    [10-Nov-2010 14:31:23] about to start loop: permalink structure: /archives/%post_id%
    [10-Nov-2010 14:31:38] about to start loop: permalink structure:
    [10-Nov-2010 14:31:40] about to start loop: permalink structure:
    [10-Nov-2010 14:31:40] about to start loop: permalink structure:
    [10-Nov-2010 14:31:41] about to start loop: permalink structure:
    [10-Nov-2010 14:31:41] about to start loop: permalink structure:
    [10-Nov-2010 14:31:42] about to start loop: permalink structure:
    [10-Nov-2010 14:31:43] about to start loop: permalink structure:
    [10-Nov-2010 14:31:45] about to start loop: permalink structure:

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WordPress core overload?’ is closed to new replies.