How To Load External Url's Data Without Slow Load? (4 posts)

  1. jbh
    Posted 5 years ago #


    A plug-in I am developing uses

    $request = new WP_Http;

    to make a connection to another url on the site, which loads calendar data relevant to each blog page that loads, but it takes forever. I tried curl earlier and that wasn't a huge help either. This server doesn't seem to load dynamic full url includes.

    Anyway, how would you load external data, such as for a PHP Calendar script, if you wanted your blog posts to load quickly?

    It's brutal for me right now. Granted, I have work to do to make sure I use conditionals so I load only one connection request per page (it's in development and there are 3 connection requests right now so maybe that's adding to load time)

    Here is what I do:

    if( !class_exists( 'WP_Http' ) )
    include_once( ABSPATH . WPINC. '/class-http.php' );


    $request = new WP_Http;
    $result = $request->request( $url1 );
    $result2 = $request->request( $url2 );
    $result3 = $request->request( $url3 );

    And then I do a replace function where I tell $content=str_replace

    and it loads the external data of the url.

    How can I do this same thing, replace a token with external url data, without a horrendous load time?


  2. digitaldonkey
    Posted 5 years ago #

    Got the same Problem.
    I to reduce load I stored the WP_http-Object in a $_SESSION, but it takes still too long.

  3. Aaron Edwards
    Posted 5 years ago #

    You should cache external data in a transient, just like WP does with the RSS widgets.

  4. digitaldonkey
    Posted 5 years ago #

    Sounds good. Never saw the "Transients API" before.
    I'll try :)

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.