Services_Digg
[ class tree: Services_Digg ] [ index: Services_Digg ] [ all elements ]

Class: Services_Digg_Request

Source Location: /Services_Digg-0.4.7/Services/Digg/Request.php

Class Overview


A class for running parallel requests to the API


Author(s):

Methods


Inherited Variables

Inherited Methods


Class Details

[line 66]
A class for running parallel requests to the API

This class allows you to send parallel asynchronous requests to the Digg API without locking your script waiting for those requests to return.

  1.  <?php
  2.  
  3.  // Make sure your keys are valid PHP variable names so it doesn't throw
  4.  // an error when trying to access the results later on.
  5.  $endPoints = array(
  6.      'popular' => Services_Digg_Request::buildCall('/stories/popular'),
  7.      'errors'  => Services_Digg_Request::buildCall('/errors'),
  8.      'topics'  => Services_Digg_Request::buildCall('/topics')
  9.  );
  10.  
  11.  // Start the requests. You'll want to run this at the very top of your
  12.  // script so that the parallel requests start working immediately.
  13.  $req = new Services_Digg_Request($endPoints);
  14.  
  15.  // The calls are asynchronous and ran in parallel so keep on working on
  16.  // other stuff while that runs in the background.
  17.  
  18.  // Now I need the popular stories
  19.  foreach ($req->popular->stories as $story{
  20.      echo '<h2>' $story->title . '</h2>' "\n";
  21.  }
  22.  
  23.  ?>

Keep in mind that the requests to the API run both in parallel and asynchronously in the background. This means that calls to the API are no longer blocking and only take as long as the slowest API request.



[ Top ]


Method Detail

__construct (Constructor)   [line 103]

void __construct( array $urls)

Constructor

Create an instance of parallel asynchronous requests to the Digg API by passing an array of endpoints keyed by a valid PHP variable name.

  • Access: public

Parameters:

array   $urls   —  Array of endpoints keyed by name

[ Top ]

__destruct (Destructor)   [line 210]

void __destruct( )

Destructor

Closes any sockets that might still be open at the end of the script or when the variable is overwritten.

  • Access: public

[ Top ]

buildCall   [line 228]

string buildCall( string $endPoint, [array $params = array()])

Builds a raw call to the API
  • Return: The RAW response with your API key, etc.
  • Access: public

Parameters:

string   $endPoint   —  API endpoint (e.g. /topics)
array   $params   —  GET parameters key/value pair

[ Top ]

__get   [line 169]

mixed __get( string $name)

Read results back in via getter

When you create your parallel request you need to add keys to the array of endpoints, which you'll reference with the getter. If the result has not been parsed yet it will be read from the stream and then parsed.

  • Return: The result object or an exception on error
  • Access: public

Parameters:

string   $name   —  Name of request

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:32:20 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.