Block until API result cached, then re-instantiate API class

From: Date: Fri, 17 Jul 2015 12:32:55 +0000
Subject: Block until API result cached, then re-instantiate API class
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-324999@lists.php.net to get a copy of this message
Hello fellow coders. What I’m trying to do is make a call to an API, cache the results and potentially it again. The Mindbody API only allows one concurrent call. I asked on Stackoverflow: http://stackoverflow.com/questions/31466667/block-until-api-result-cached-then-re-instantiate-api-class This is the code: https://github.com/MikeiLL/wp-mindbody-plugin/blob/dev/inc/mz_schedule.php Using a Class to make a call to a SOAP API (MindbodyOnline) which can only have a single connection per instance (API methods will not be available upon additional concurrent calls), but I want to be able to have multiple instances of various resulting data. I am using wordpress _transients to store the result in a database, and can actually get multiple "instances" by: call the function once (with a shortcode) load the page (creating a cached version) call function a second time (second shortcode) reload the page Now there are two separate cached versions of the API result. But this is not a working solution for many reasons. From my limited understanding of how php works, all of the "page code" is interpreted and compiled as C code, then run at the same time. Is this correct? Is there some way to make a class with a method that will: Instantiate the class which calls the API Cache the result For each time it is called within a page? Maybe something along these lines: if ( false === ( $staff = get_transient( $mz_staff_cache ) ) ) { $mb = instantiate_mbo_API(); // function instantiates API class /* Some check here to see if we need to call API again * and re-instantiate somehow if we do? */ $staff = $mb->GetStaff(); // This is an API class method set_transient($mz_staff_cache, $staff, 60 * 60 * 24); } // Do stuff with $staff I’m thinking running multiple API queries with AJAX might be an answer, but sending information back and forth from the browser multiple times doesn’t seem quite right. It’s a wordpress plugin so that limits the possibilities in ways - like calling a sub-process to C or python or something wouldn’t work. Any thoughts? Thanks. Mike Michael Kilmer Media Zen Organic Outreach Music, Theater, Multimedia and Web Development info@mzoo.org 201-679-4168 www.mZoo.org www.madhappy.com www.rivka.com

Attachment: [application/pgp-signature] Message signed with OpenPGP using GPGMail signature.asc
« previous php.general (#324999) next »