@ 2015-05-03T20:17:05Z <?php
# initialize JSON-RPC client
$api_key = '161ff5c48a60fdda9bd31da09e0c4224'; //Place API key here
$api_url = 'http://api2.getresponse.com';
$client = new jsonRPCClient($api_url);
try {
$name = array();
$result = $client->get_campaigns($api_key);
//Get Campaigns name and id.
foreach($result as $r){
$name = $r['name'];
print "List Name --> " . $name; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' '; echo ' ';
$result2 = $client->get_campaigns(
$api_key,
array (
'name' => array ( 'EQUALS' => $name )
)
);
$res = array_keys($result2);
$CAMPAIGN_IDs = array_pop($res);
print "List ID --> " . $CAMPAIGN_IDs;
echo "<br>";
}
}
catch (Exception $e) {
echo $e->getMessage();
}
?>
<?php
/**
* jsonRPCClient.php
*
* Written using the JSON RPC specification -
* http://json-rpc.org/wiki/specification
*
*/
class jsonRPCClient
{
protected $url = null, $is_notification = false, $is_debug = false;
// http errors - more can be found at
// http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
public $http_errors = array
(
400 => '400 Bad Request',
500 => '500 Internal Server Error'
);
/**
* Takes the connection parameter and checks for extentions
*
* @param string $url - url name like http://example.com/
* @return void
*/
public function __construct( $url )
{
$validateParams = array
(
false === extension_loaded('curl') => 'The curl extension must be loaded for using this class !',
false === extension_loaded('json') => 'The json extension must be loaded for using this class !'
);
$this->checkForErrors( $validateParams );
// set an url to connect to
$this->url = $url;
}
/**
* Set debug mode
*
* @param boolean $is_debug
* @return void
*/
public function setDebug( $is_debug )
{
$this->is_debug = !empty($is_debug);
}
/**
* Set request to be a notification
*
* @param boolean $is_notification
* @return void
*/
public function setNotification( $is_notification )
{
$this->is_is_notification = !empty($is_notification);
}
/**
* Performs a request and gets the results
*
* @param string $method - A String containing the name of the method to be invoked.
* @param array $params - An Array of objects to pass as arguments to the method.
* @return array
*/
public function __call( $method, $params )
{
static $counter;
// check if given params are correct
$validateParams = array
(
false === is_scalar($method) => 'Method name has no scalar value',
false === is_array($params) => 'Params must be given as array'
);
$this->checkForErrors( $validateParams );
// if this is_notification - JSON-RPC specification point 1.3
$requestId = true === $this->is_notification ? null : ++$counter;
// Request (method invocation) - JSON-RPC specification point 1.1
$request = json_encode( array ( 'method' => $method, 'params' => array_values($params), 'id' => $requestId ) );
// if is_debug mode is true then add request to is_debug
$this->debug( 'Request: ' . $request . "\r\n", false );
$response = $this->getResponse( $request );
// if is_debug mode is true then add response to is_debug and display it
$this->debug( 'Response: ' . $response . "\r\n", true );
// decode and create array ( can be object, just set to false )
$response = json_decode( utf8_encode($response), true );
// if this was just is_notification
if ( true === $this->is_notification )
{
return true;
}
// check if response is correct
$validateParams = array
(
!is_null($response['error']) => 'Request have return error: ' . $response['error'],
$response['id'] != $requestId => 'Request id: '.$requestId.'is different from Response id: ' . $response['id'],
);
$this->checkForErrors( $validateParams );
return $response['result'];
}
/**
* When the method invocation completes, the service must reply with a response.
* The response is a single object serialized using JSON
*
* @param string $request
* @return string
*/
protected function & getResponse( & $request )
{
// do the actual connection
$ch = curl_init();
// set URL
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_HEADER, 'Content-type: application/json;');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// send the request
$response = curl_exec($ch);
// check http status code
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ( isset($this->http_errors[$http_code]) )
{
throw new Exception('Response Http Error - ' . $this->http_errors[$http_code] );
}
// check for curl error
if ( 0 < curl_errno($ch) )
{
throw new Exception('Unable to connect to '.$this->url . ' Error: ' . curl_error($ch) );
}
// close the connection
curl_close($ch);
return $response;
}
/**
* Check for errors
*
* @param array $validateArray
* @return void
*/
protected function checkForErrors( & $validateArray )
{
foreach ( $validateArray as $test => $error )
{
if ( $test )
{
throw new Exception( $error );
}
}
}
/**
* For is_debug and performance stats
*
* @param string $add
* @param boolean $show
* @return void
*/
protected function debug( $add, $show = false )
{
static $debug, $startTime;
// is_debug off return
if ( false === $this->is_debug )
{
return;
}
// add
$debug .= $add;
// get starttime
$startTime = empty($startTime) ? array_sum(explode(' ', microtime())) : $startTime;
if ( true === $show and !empty($debug) )
{
// get endtime
$endTime = array_sum(explode(' ', microtime()));
// performance summary
$debug .= 'Request time: ' . round($endTime - $startTime, 3) . ' s Memory usage: ' . round(memory_get_usage() / 1024) . " kb\r\n";
echo nl2br($debug);
// send output imidiately
flush();
// clean static
$debug = $startTime = null;
}
}
}
?>
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.4.0 0.010 0.007 14.80 7.3.12 0.006 0.010 14.89 7.3.11 0.012 0.006 14.82 7.3.10 0.006 0.008 15.05 7.3.9 0.008 0.005 14.97 7.3.8 0.009 0.007 14.78 7.3.7 0.008 0.005 14.79 7.3.6 0.005 0.010 14.93 7.3.5 0.010 0.005 14.78 7.3.4 0.005 0.010 14.72 7.3.3 0.005 0.005 14.76 7.3.2 0.006 0.008 16.68 7.3.1 0.005 0.009 16.59 7.3.0 0.006 0.010 16.73 7.2.25 0.009 0.006 15.31 7.2.24 0.000 0.017 15.16 7.2.23 0.008 0.005 14.94 7.2.22 0.005 0.009 15.25 7.2.21 0.004 0.010 15.18 7.2.20 0.004 0.011 15.07 7.2.19 0.003 0.012 15.11 7.2.18 0.010 0.006 15.25 7.2.17 0.002 0.014 15.01 7.2.16 0.000 0.016 14.83 7.2.15 0.006 0.006 16.96 7.2.14 0.014 0.000 16.84 7.2.13 0.010 0.003 16.87 7.2.12 0.008 0.005 16.97 7.2.11 0.007 0.007 17.03 7.2.10 0.007 0.007 16.95 7.2.9 0.005 0.009 16.94 7.2.8 0.000 0.012 16.91 7.2.7 0.004 0.008 16.76 7.2.6 0.010 0.005 16.76 7.2.5 0.005 0.007 16.83 7.2.4 0.002 0.010 16.93 7.2.3 0.007 0.007 16.91 7.2.2 0.006 0.006 16.98 7.2.1 0.004 0.011 16.93 7.2.0 0.004 0.008 17.67 7.1.33 0.006 0.010 15.88 7.1.32 0.000 0.012 15.78 7.1.31 0.003 0.008 15.78 7.1.30 0.002 0.008 15.63 7.1.29 0.003 0.008 15.66 7.1.28 0.008 0.006 15.80 7.1.27 0.007 0.007 15.80 7.1.26 0.003 0.011 15.94 7.1.25 0.006 0.008 15.82 7.1.7 0.004 0.004 17.06 7.1.6 0.006 0.019 19.50 7.1.5 0.009 0.013 16.86 7.1.0 0.000 0.080 22.32 7.0.20 0.023 0.010 15.07 7.0.14 0.000 0.077 22.11 7.0.9 0.013 0.080 19.98 7.0.8 0.023 0.090 20.01 7.0.7 0.000 0.053 20.03 7.0.6 0.013 0.043 20.07 7.0.5 0.020 0.063 20.42 7.0.4 0.003 0.047 20.09 7.0.3 0.013 0.040 20.09 7.0.2 0.010 0.080 20.14 7.0.1 0.013 0.073 20.07 7.0.0 0.003 0.083 20.04 5.6.28 0.007 0.070 21.04 5.6.24 0.020 0.060 20.67 5.6.23 0.000 0.050 20.68 5.6.22 0.000 0.087 20.62 5.6.21 0.013 0.073 20.66 5.6.20 0.010 0.083 20.96 5.6.19 0.000 0.050 21.09 5.6.18 0.013 0.073 21.08 5.6.17 0.010 0.067 21.05 5.6.16 0.007 0.073 21.00 5.6.15 0.010 0.077 21.10 5.6.14 0.017 0.073 21.18 5.6.13 0.010 0.087 21.13 5.6.12 0.017 0.073 21.05 5.6.11 0.000 0.057 21.06 5.6.10 0.017 0.070 21.07 5.6.9 0.017 0.053 20.97 5.6.8 0.007 0.043 20.37 5.6.7 0.007 0.060 20.52 5.6.6 0.017 0.047 20.43 5.6.5 0.013 0.063 20.48 5.6.4 0.007 0.080 20.43 5.6.3 0.010 0.073 20.47 5.6.2 0.000 0.057 20.43 5.6.1 0.010 0.080 20.44 5.6.0 0.000 0.060 20.44 5.5.38 0.007 0.040 20.54 5.5.37 0.010 0.080 20.41 5.5.36 0.007 0.050 20.53 5.5.35 0.007 0.080 20.37 5.5.34 0.013 0.077 20.78 5.5.33 0.013 0.070 20.78 5.5.32 0.007 0.083 20.82 5.5.31 0.007 0.083 20.95 5.5.30 0.003 0.067 20.84 5.5.29 0.000 0.050 20.69 5.5.28 0.020 0.073 20.86 5.5.27 0.013 0.073 20.89 5.5.26 0.017 0.077 20.77 5.5.25 0.013 0.077 20.50 5.5.24 0.010 0.050 20.29 5.5.23 0.007 0.083 20.18 5.5.22 0.017 0.073 20.19 5.5.21 0.007 0.077 20.34 5.5.20 0.003 0.073 20.26 5.5.19 0.013 0.037 20.29 5.5.18 0.010 0.043 20.04 5.5.16 0.007 0.077 20.27 5.5.15 0.003 0.047 20.29 5.5.14 0.007 0.073 20.22 5.5.13 0.007 0.083 20.18 5.5.12 0.010 0.070 20.23 5.5.11 0.010 0.073 20.28 5.5.10 0.013 0.070 20.20 5.5.9 0.017 0.070 20.17 5.5.8 0.010 0.077 20.20 5.5.7 0.010 0.073 20.01 5.5.6 0.013 0.070 20.07 5.5.5 0.003 0.077 20.14 5.5.4 0.010 0.067 19.99 5.5.3 0.010 0.057 20.18 5.5.2 0.013 0.057 20.08 5.5.1 0.010 0.083 20.07 5.5.0 0.003 0.057 20.04 5.4.45 0.023 0.067 19.45 5.4.44 0.003 0.050 19.40 5.4.43 0.010 0.083 19.17 5.4.42 0.007 0.053 19.50 5.4.41 0.013 0.053 19.40 5.4.40 0.013 0.070 19.06 5.4.39 0.013 0.073 19.01 5.4.38 0.003 0.080 18.86 5.4.37 0.017 0.067 19.21 5.4.36 0.007 0.037 19.23 5.4.35 0.003 0.057 19.05 5.4.34 0.017 0.077 19.03 5.4.32 0.013 0.043 19.15 5.4.31 0.017 0.070 19.00 5.4.30 0.013 0.060 19.12 5.4.29 0.010 0.040 19.09 5.4.28 0.007 0.060 19.18 5.4.27 0.007 0.053 18.94 5.4.26 0.017 0.067 19.08 5.4.25 0.010 0.043 19.17 5.4.24 0.010 0.073 18.94 5.4.23 0.007 0.043 18.87 5.4.22 0.013 0.037 19.04 5.4.21 0.017 0.067 19.04 5.4.20 0.007 0.073 19.24 5.4.19 0.000 0.047 19.13 5.4.18 0.003 0.043 19.18 5.4.17 0.010 0.040 18.89 5.4.16 0.013 0.073 19.02 5.4.15 0.007 0.040 18.88 5.4.14 0.000 0.043 16.42 5.4.13 0.013 0.033 16.25 5.4.12 0.007 0.067 16.48 5.4.11 0.010 0.070 16.59 5.4.10 0.003 0.077 16.54 5.4.9 0.003 0.070 16.42 5.4.8 0.007 0.063 16.29 5.4.7 0.000 0.080 16.55 5.4.6 0.010 0.063 16.39 5.4.5 0.013 0.060 16.34 5.4.4 0.017 0.063 16.49 5.4.3 0.003 0.050 16.54 5.4.2 0.000 0.070 16.50 5.4.1 0.010 0.060 16.34 5.4.0 0.007 0.040 15.89
preferences:dark mode live preview
35.63 ms | 403 KiB | 5 Q