3v4l.org

run code in 300+ PHP versions simultaneously
<?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 '&nbsp'; echo '&nbsp'; echo '&nbsp'; echo '&nbsp'; echo '&nbsp'; echo '&nbsp'; echo '&nbsp'; echo '&nbsp'; $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; } } } ?>

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).

VersionSystem time (s)User time (s)Memory (MiB)
7.4.00.0100.00714.80
7.3.120.0060.01014.89
7.3.110.0120.00614.82
7.3.100.0060.00815.05
7.3.90.0080.00514.97
7.3.80.0090.00714.78
7.3.70.0080.00514.79
7.3.60.0050.01014.93
7.3.50.0100.00514.78
7.3.40.0050.01014.72
7.3.30.0050.00514.76
7.3.20.0060.00816.68
7.3.10.0050.00916.59
7.3.00.0060.01016.73
7.2.250.0090.00615.31
7.2.240.0000.01715.16
7.2.230.0080.00514.94
7.2.220.0050.00915.25
7.2.210.0040.01015.18
7.2.200.0040.01115.07
7.2.190.0030.01215.11
7.2.180.0100.00615.25
7.2.170.0020.01415.01
7.2.160.0000.01614.83
7.2.150.0060.00616.96
7.2.140.0140.00016.84
7.2.130.0100.00316.87
7.2.120.0080.00516.97
7.2.110.0070.00717.03
7.2.100.0070.00716.95
7.2.90.0050.00916.94
7.2.80.0000.01216.91
7.2.70.0040.00816.76
7.2.60.0100.00516.76
7.2.50.0050.00716.83
7.2.40.0020.01016.93
7.2.30.0070.00716.91
7.2.20.0060.00616.98
7.2.10.0040.01116.93
7.2.00.0040.00817.67
7.1.330.0060.01015.88
7.1.320.0000.01215.78
7.1.310.0030.00815.78
7.1.300.0020.00815.63
7.1.290.0030.00815.66
7.1.280.0080.00615.80
7.1.270.0070.00715.80
7.1.260.0030.01115.94
7.1.250.0060.00815.82
7.1.70.0040.00417.06
7.1.60.0060.01919.50
7.1.50.0090.01316.86
7.1.00.0000.08022.32
7.0.200.0230.01015.07
7.0.140.0000.07722.11
7.0.90.0130.08019.98
7.0.80.0230.09020.01
7.0.70.0000.05320.03
7.0.60.0130.04320.07
7.0.50.0200.06320.42
7.0.40.0030.04720.09
7.0.30.0130.04020.09
7.0.20.0100.08020.14
7.0.10.0130.07320.07
7.0.00.0030.08320.04
5.6.280.0070.07021.04
5.6.240.0200.06020.67
5.6.230.0000.05020.68
5.6.220.0000.08720.62
5.6.210.0130.07320.66
5.6.200.0100.08320.96
5.6.190.0000.05021.09
5.6.180.0130.07321.08
5.6.170.0100.06721.05
5.6.160.0070.07321.00
5.6.150.0100.07721.10
5.6.140.0170.07321.18
5.6.130.0100.08721.13
5.6.120.0170.07321.05
5.6.110.0000.05721.06
5.6.100.0170.07021.07
5.6.90.0170.05320.97
5.6.80.0070.04320.37
5.6.70.0070.06020.52
5.6.60.0170.04720.43
5.6.50.0130.06320.48
5.6.40.0070.08020.43
5.6.30.0100.07320.47
5.6.20.0000.05720.43
5.6.10.0100.08020.44
5.6.00.0000.06020.44
5.5.380.0070.04020.54
5.5.370.0100.08020.41
5.5.360.0070.05020.53
5.5.350.0070.08020.37
5.5.340.0130.07720.78
5.5.330.0130.07020.78
5.5.320.0070.08320.82
5.5.310.0070.08320.95
5.5.300.0030.06720.84
5.5.290.0000.05020.69
5.5.280.0200.07320.86
5.5.270.0130.07320.89
5.5.260.0170.07720.77
5.5.250.0130.07720.50
5.5.240.0100.05020.29
5.5.230.0070.08320.18
5.5.220.0170.07320.19
5.5.210.0070.07720.34
5.5.200.0030.07320.26
5.5.190.0130.03720.29
5.5.180.0100.04320.04
5.5.160.0070.07720.27
5.5.150.0030.04720.29
5.5.140.0070.07320.22
5.5.130.0070.08320.18
5.5.120.0100.07020.23
5.5.110.0100.07320.28
5.5.100.0130.07020.20
5.5.90.0170.07020.17
5.5.80.0100.07720.20
5.5.70.0100.07320.01
5.5.60.0130.07020.07
5.5.50.0030.07720.14
5.5.40.0100.06719.99
5.5.30.0100.05720.18
5.5.20.0130.05720.08
5.5.10.0100.08320.07
5.5.00.0030.05720.04
5.4.450.0230.06719.45
5.4.440.0030.05019.40
5.4.430.0100.08319.17
5.4.420.0070.05319.50
5.4.410.0130.05319.40
5.4.400.0130.07019.06
5.4.390.0130.07319.01
5.4.380.0030.08018.86
5.4.370.0170.06719.21
5.4.360.0070.03719.23
5.4.350.0030.05719.05
5.4.340.0170.07719.03
5.4.320.0130.04319.15
5.4.310.0170.07019.00
5.4.300.0130.06019.12
5.4.290.0100.04019.09
5.4.280.0070.06019.18
5.4.270.0070.05318.94
5.4.260.0170.06719.08
5.4.250.0100.04319.17
5.4.240.0100.07318.94
5.4.230.0070.04318.87
5.4.220.0130.03719.04
5.4.210.0170.06719.04
5.4.200.0070.07319.24
5.4.190.0000.04719.13
5.4.180.0030.04319.18
5.4.170.0100.04018.89
5.4.160.0130.07319.02
5.4.150.0070.04018.88
5.4.140.0000.04316.42
5.4.130.0130.03316.25
5.4.120.0070.06716.48
5.4.110.0100.07016.59
5.4.100.0030.07716.54
5.4.90.0030.07016.42
5.4.80.0070.06316.29
5.4.70.0000.08016.55
5.4.60.0100.06316.39
5.4.50.0130.06016.34
5.4.40.0170.06316.49
5.4.30.0030.05016.54
5.4.20.0000.07016.50
5.4.10.0100.06016.34
5.4.00.0070.04015.89

preferences:
41.17 ms | 401 KiB | 5 Q