WordPress.org

Forums

Why does wp_insert_post() take 4.5 minutes? (6 posts)

  1. ratbastid
    Member
    Posted 8 years ago #

    I have a plugin that inserts a post. It used to run fast, but now it takes upwards of 8 minutes to do its job. I've used time() to calculate execution times at various stages. The part that I expected to be slow (using GD to resize images) is actually real quick. What kills me is one call to wp_insert_post() that reliably takes 259 seconds.

    Following that call, I use $wpdb to insert two categories for this post and 7 postmeta values. All that database work takes ANOTHER 258 seconds. Those two numbers are suspiciously close.

    Also, posting a post in the admin interface takes a hellatiously long time too. Obviously I haven't hacked into the core code to profile it, but I'd say it's taking at least several minutes.

    I've run myisamchk on my databases. Several say that they are usable but could stand fixing. You think running repairs on the database might fix this?

  2. Chris_K
    Member
    Posted 8 years ago #

    Try timing it with nothing in "Update Services" at Options -> Writing.

  3. ratbastid
    Member
    Posted 8 years ago #

    Oh. My. God.

    My client had 64 ping targets in there. Sixty-effing-four. He's SO fired.

    Clearing them out makes my posting go lickety-split. I'm glad I just spent my whole day hacking a mechanism to make the posting happen in the background.

    Thanks for your help HandySolo.

  4. Chris_K
    Member
    Posted 8 years ago #

    So glad to help. :-)

    And hey, that reminds me (if you're still working on the background thing) that there is a plugin floating around that'll do just that: All the pings in the background. NoPingWait I think it's called?

  5. eduo
    Member
    Posted 8 years ago #

    Incidentally, letting us know about the plugin would be nice. I have to do a plugin that automatically inserts a post every week and it seems wp_insert_post() is not documented anywhere I can find.

  6. whooami
    Member
    Posted 8 years ago #

    The plugin isn't necessary - you replied to a post that is 5 months old. Since that last post, several versions of WP have come out and outbound pings are handled completely differently and no longer affect post insertion times

Topic Closed

This topic has been closed to new replies.

About this Topic