WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. jbh
    Member
    Posted 3 years ago #

    Hey,

    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' );

    $url1="http://www.site1.com/page1.html";
    $url2=".../page2.html";
    $url3=".../page3.html";

    $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
    ("[token_in_page]",$result[body],$content)

    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?

    Thanks

  2. digitaldonkey
    Member
    Posted 3 years ago #

    Anyone?
    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
    Member
    Posted 3 years ago #

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

  4. digitaldonkey
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.