3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Super-simple, minimum abstraction MailChimp API v3 wrapper * * Uses curl if available, falls back to file_get_contents and HTTP stream. * This probably has more comments than code. * * @author Drew McLellan <drew.mclellan@gmail.com> * @version 2.0 */ class MailChimp { private $api_key; private $api_endpoint = 'https://<dc>.api.mailchimp.com/3.0'; private $verify_ssl = true; /** * Create a new instance * @param string $api_key Your MailChimp API key */ public function __construct($api_key) { $this->api_key = $api_key; list(, $datacentre) = explode('-', $this->api_key); $this->api_endpoint = str_replace('<dc>', $datacentre, $this->api_endpoint); } public function delete($method, $args=array(), $timeout=10) { return $this->makeRequest('delete', $method, $args, $timeout); } public function get($method, $args=array(), $timeout=10) { return $this->makeRequest('get', $method, $args, $timeout); } public function patch($method, $args=array(), $timeout=10) { return $this->makeRequest('patch', $method, $args, $timeout); } public function post($method, $args=array(), $timeout=10) { return $this->makeRequest('post', $method, $args, $timeout); } public function put($method, $args=array(), $timeout=10) { return $this->makeRequest('put', $method, $args, $timeout); } /** * Performs the underlying HTTP request. Not very exciting * @param string $$http_verb The HTTP verb to use: get, post, put, patch, delete * @param string $method The API method to be called * @param array $args Assoc array of parameters to be passed * @return array Assoc array of decoded result */ private function makeRequest($http_verb, $method, $args=array(), $timeout=10) { $args['apikey'] = $this->api_key; $url = $this->api_endpoint.'/'.$method; $json_data = json_encode((object)$args); if (function_exists('curl_init') && function_exists('curl_setopt')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, 'drewm:'.$this->api_key); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/vnd.api+json', 'Content-Type: application/vnd.api+json')); curl_setopt($ch, CURLOPT_USERAGENT, 'DrewM/MailChimp-API/3.0 (github.com/drewm/mailchimp-api)'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verify_ssl); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0); switch($http_verb) { case 'post': curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); break; case 'get': $query = http_build_query($args); curl_setopt($ch, CURLOPT_URL, $url.'?'.$query); break; case 'delete': curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); break; case 'patch': curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); break; } $result = curl_exec($ch); curl_close($ch); } else { throw new Exception("cURL support is required, but can't be found."); } return $result ? json_decode($result, true) : false; } } // MailChimp Configuration $api_key = "f36426878616bc7a2e1fc918ab9f9de5-us12"; // ENTER YOUR API KEY HERE $list_id = "d7973804f4"; // ENTER YOUR LIST ID HERE $MailChimp = new MailChimp($api_key); $result = $MailChimp->post('lists/' .$list_id. '/members', array( 'email_address' => 'rajan@gmail.com', 'status' => 'subscribed' )); if($result['status'] == 'subscribed') { echo json_encode(array('error' => false, 'message' => 'Thanks for subscribing with us')); exit; } else { echo json_encode(array('error' => true, 'message' => $result['title'])); exit; }

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)
8.3.60.0070.01017.00
8.3.50.0140.00822.05
8.3.40.0110.00419.09
8.3.30.0070.00718.84
8.3.20.0040.00420.28
8.3.10.0040.00423.66
8.3.00.0040.00419.34
8.2.180.0070.01118.66
8.2.170.0090.01222.96
8.2.160.0110.00420.52
8.2.150.0030.00624.18
8.2.140.0040.00424.66
8.2.130.0000.00826.16
8.2.120.0100.00317.75
8.2.110.0090.00322.16
8.2.100.0060.00618.05
8.2.90.0050.00319.16
8.2.80.0050.00317.97
8.2.70.0060.00317.75
8.2.60.0000.00818.18
8.2.50.0060.00318.07
8.2.40.0040.00419.19
8.2.30.0020.00520.79
8.2.20.0040.00417.83
8.2.10.0000.00818.25
8.2.00.0000.00718.21
8.1.280.0100.01025.92
8.1.270.0040.00423.88
8.1.260.0000.00826.35
8.1.250.0080.00028.09
8.1.240.0030.00622.64
8.1.230.0070.00417.88
8.1.220.0080.00017.91
8.1.210.0060.00318.77
8.1.200.0060.00317.38
8.1.190.0060.00317.46
8.1.180.0040.00418.10
8.1.170.0000.00818.71
8.1.160.0030.00621.98
8.1.150.0050.00318.88
8.1.140.0050.00319.71
8.1.130.0000.00717.69
8.1.120.0070.00017.61
8.1.110.0000.00717.46
8.1.100.0000.00717.56
8.1.90.0000.00717.61
8.1.80.0060.00317.62
8.1.70.0030.00517.57
8.1.60.0040.00417.74
8.1.50.0060.00617.64
8.1.40.0000.01217.63
8.1.30.0080.00017.64
8.1.20.0040.00417.74
8.1.10.0060.00317.68
8.1.00.0040.00817.57
8.0.300.0000.00718.77
8.0.290.0000.00916.88
8.0.280.0050.00218.54
8.0.270.0070.00017.34
8.0.260.0060.00017.46
8.0.250.0030.00517.15
8.0.240.0000.00817.09
8.0.230.0000.00817.11
8.0.220.0040.00417.05
8.0.210.0000.00817.11
8.0.200.0000.00717.10
8.0.190.0030.00517.10
8.0.180.0050.00217.07
8.0.170.0080.00017.17
8.0.160.0040.00416.94
8.0.150.0040.00416.93
8.0.140.0040.00416.97
8.0.130.0060.00013.44
8.0.120.0060.00316.99
8.0.110.0000.00717.04
8.0.100.0040.00416.96
8.0.90.0040.00416.85
8.0.80.0100.00717.04
8.0.70.0080.00016.95
8.0.60.0040.00417.11
8.0.50.0040.00416.89
8.0.30.0190.00217.12
8.0.20.0080.01017.40
8.0.10.0030.00517.24
8.0.00.0080.00916.80
7.4.330.0030.00315.16
7.4.320.0040.00416.62
7.4.300.0060.00016.70
7.4.290.0030.00316.72
7.4.280.0000.00816.51
7.4.270.0040.00416.63
7.4.260.0080.00016.60
7.4.250.0070.00016.50
7.4.240.0010.00616.63
7.4.230.0000.00716.60
7.4.220.0100.01016.54
7.4.210.0090.00616.64
7.4.200.0020.00516.63
7.4.160.0100.01016.62
7.4.150.0070.01117.40
7.4.140.0120.00917.86
7.4.130.0110.00716.71
7.4.120.0070.01016.58
7.4.110.0070.01416.75
7.4.100.0090.00916.56
7.4.90.0170.00016.59
7.4.80.0120.00619.39
7.4.70.0090.00916.57
7.4.60.0110.00516.61
7.4.50.0050.00316.53
7.4.40.0170.00716.69
7.4.30.0070.01316.66
7.4.00.0040.00414.98
7.3.330.0030.00313.50
7.3.320.0060.00013.52
7.3.310.0020.00516.39
7.3.300.0000.00716.53
7.3.290.0070.01016.50
7.3.280.0070.01116.50
7.3.270.0080.01117.40
7.3.260.0060.01216.77
7.3.240.0030.01416.47
7.3.230.0030.01316.49
7.3.210.0040.01316.51
7.3.200.0070.01016.74
7.3.190.0030.01316.52
7.3.180.0090.00916.48
7.3.170.0100.00716.55
7.3.160.0060.01016.64
7.3.10.0030.00716.54
7.3.00.0080.00316.75
7.2.330.0150.00316.61
7.2.320.0110.00716.84
7.2.310.0150.00316.91
7.2.300.0060.01316.54
7.2.290.0070.01016.70
7.2.130.0100.00516.75
7.2.120.0040.01216.95
7.2.110.0080.00816.44
7.2.100.0090.00616.90
7.2.90.0030.00616.96
7.2.80.0040.01416.66
7.2.70.0060.00916.77
7.2.60.0070.00716.82
7.2.50.0060.00916.75
7.2.40.0090.00316.55
7.2.30.0000.01416.73
7.2.20.0000.01416.73
7.2.10.0000.01616.82
7.2.00.0080.00816.89
7.1.250.0080.00415.68
7.1.200.0030.01015.55
7.1.100.0110.00717.91
7.1.70.0030.01017.01
7.1.60.0110.01419.43
7.1.50.0100.01016.94
7.1.00.0000.08022.33
7.0.200.3950.00314.88
7.0.90.0130.03720.07
7.0.80.0030.04019.97
7.0.70.0070.03319.99
7.0.60.0100.07020.07
7.0.50.0030.04020.48
7.0.40.0100.08720.07
7.0.30.0070.04320.15
7.0.20.0030.04720.08
7.0.10.0070.08320.18
7.0.00.0130.07720.03
5.6.280.0070.03020.93
5.6.240.0070.08320.64
5.6.230.0100.07320.71
5.6.220.0070.03720.68
5.6.210.0000.05020.64
5.6.200.0130.07720.99
5.6.190.0130.06721.10
5.6.180.0100.03721.17
5.6.170.0030.07021.10
5.6.160.0200.07021.05
5.6.150.0100.08321.07
5.6.140.0300.03321.05
5.6.130.0030.04721.17
5.6.120.0130.08021.13
5.6.110.0070.08721.06
5.6.100.0130.07321.05
5.6.90.0000.08721.04
5.6.80.0100.05020.38
5.6.70.0070.04720.37
5.6.60.0030.04720.42
5.6.50.0000.04320.50
5.6.40.0130.07020.43
5.6.30.0170.07020.48
5.6.20.0100.04720.35
5.6.10.0130.07020.34
5.6.00.0100.07720.46
5.5.380.0070.09020.46
5.5.370.0000.08720.39
5.5.360.0000.06020.43
5.5.350.0100.03320.50
5.5.340.0100.07720.85
5.5.330.0000.07720.84
5.5.320.0070.04020.96
5.5.310.0030.08020.90
5.5.300.0070.08320.68
5.5.290.0100.04320.91
5.5.280.0130.08020.90
5.5.270.0030.08720.95
5.5.260.0070.04020.91
5.5.250.0070.07720.50
5.5.240.0030.08320.23
5.5.230.0000.08320.32
5.5.220.0070.06720.25
5.5.210.0070.04320.26
5.5.200.0100.06020.12
5.5.190.0070.07320.31
5.5.180.0100.07720.32
5.5.160.0070.06720.13
5.5.150.0030.08020.30
5.5.140.0030.05320.27
5.5.130.0170.06320.29
5.5.120.0100.07320.17
5.5.110.0100.07320.25
5.5.100.0000.06720.21
5.5.90.0130.07320.11
5.5.80.0070.07320.15
5.5.70.0100.06019.98
5.5.60.0070.07720.14
5.5.50.0100.07320.10
5.5.40.0030.04720.09
5.5.30.0070.06319.98
5.5.20.0070.04020.12
5.5.10.0070.08320.09
5.5.00.0030.07320.08
5.4.450.0070.04019.54
5.4.440.0030.04319.20
5.4.430.0130.06719.55
5.4.420.0000.04319.37
5.4.410.0070.08019.23
5.4.400.0130.03019.10
5.4.390.0070.04019.18
5.4.380.0030.04318.94
5.4.370.0070.07019.21
5.4.360.0070.08319.14
5.4.350.0030.06319.07
5.4.340.0130.07319.09
5.4.320.0070.06718.88
5.4.310.0130.05318.89
5.4.300.0070.05719.05
5.4.290.0270.05719.23
5.4.280.0130.05019.02
5.4.270.0070.04019.04
5.4.260.0070.04719.07
5.4.250.0100.07019.22
5.4.240.0070.06318.86
5.4.230.0030.05019.23
5.4.220.0100.07319.12
5.4.210.0130.05319.11
5.4.200.0100.07319.02
5.4.190.0030.08019.13
5.4.180.0070.07019.02
5.4.170.0070.05319.20
5.4.160.0100.06719.23
5.4.150.0130.06018.93
5.4.140.0070.03716.47
5.4.130.0030.07016.42
5.4.120.0100.06016.32
5.4.110.0130.04316.51
5.4.100.0000.04716.34
5.4.90.0070.06316.34
5.4.80.0100.06016.51
5.4.70.0070.06716.42
5.4.60.0100.03716.36
5.4.50.0130.04316.40
5.4.40.0130.06716.29
5.4.30.0100.06716.49
5.4.20.0030.07316.50
5.4.10.0130.06316.44
5.4.00.0030.05315.62

preferences:
32.6 ms | 401 KiB | 5 Q