3v4l.org

run code in 300+ PHP versions simultaneously
<?php class PostcodeNl_Api_Helper_Data extends Mage_Core_Helper_Abstract { const API_TIMEOUT = 3; const API_URL = 'https://api.postcode.nl'; protected $_modules; protected function _getMagentoVersion() { if ($this->_getModuleInfo('Enterprise_CatalogPermissions') !== null) { // Detect enterprise return 'MagentoEnterprise/'. Mage::getVersion(); } elseif ($this->_getModuleInfo('Enterprise_Enterprise') !== null) { // Detect professional return 'MagentoProfessional/'. Mage::getVersion(); } else { // Rest return 'Magento/'. Mage::getVersion(); } } protected function _getModuleInfo($moduleName) { if (!isset($this->_modules)) $this->_modules = (array)Mage::getConfig()->getNode('modules')->children(); if (!isset($this->_modules[$moduleName])) return null; return $this->_modules[$moduleName]; } /** * Get the html for initializing validation script. * * @return string */ public function getJsinit($getAdminConfig = false) { $getBool = function ($configKey) { if (Mage::getStoreConfig($configKey)) return 'true'; return 'false'; }; if ($getAdminConfig) $baseUrl = Mage::helper('adminhtml')->getUrl('*/pcnl/lookup', array('_secure' => true)); else $baseUrl = Mage::getUrl('postcodenl_api/json', array('_secure' => true)); $html = ' <script type="text/javascript"> //<![CDATA[ var PCNLAPI_CONFIG = { baseUrl: "' . htmlspecialchars($baseUrl) . '", adminValidationDisabled: ' . $getBool('postcodenl_api/advanced_config/admin_validation_disabled') . ', useStreet2AsHouseNumber: ' . $getBool('postcodenl_api/advanced_config/use_street2_as_housenumber') . ', blockPostOfficeBoxAddresses: '. $getBool('postcodenl_api/advanced_config/block_postofficeboxaddresses') . ', neverHideCountry: ' . $getBool('postcodenl_api/advanced_config/never_hide_country') . ', showcase: ' . $getBool('postcodenl_api/development_config/api_showcase') . ', debug: ' . $getBool('postcodenl_api/development_config/api_debug') . ', translations: { defaultError: "' . htmlspecialchars($this->__('Unknown postcode + housenumber combination.')) . '", postcodeInputLabel: "' . htmlspecialchars($this->__('Postcode')) . '", postcodeInputTitle: "' . htmlspecialchars($this->__('Postcode')) . '", houseNumberAdditionUnknown: "' . htmlspecialchars($this->__('Housenumber addition `{addition}` is unknown.')) . '", houseNumberAdditionRequired: "' . htmlspecialchars($this->__('Housenumber addition required.')) . '", houseNumberLabel: "' . htmlspecialchars($this->__('Housenumber')) . '", houseNumberTitle: "' . htmlspecialchars($this->__('Housenumber')) . '", houseNumberAdditionLabel: "' . htmlspecialchars($this->__('Housenumber addition')) . '", houseNumberAdditionTitle: "' . htmlspecialchars($this->__('Housenumber addition')) . '", selectAddition: "' . htmlspecialchars($this->__('Select...')) . '", noAdditionSelect: "' . htmlspecialchars($this->__('No addition.')) . '", noAdditionSelectCustom: "' . htmlspecialchars($this->__('`No addition`')) . '", additionSelectCustom: "' . htmlspecialchars($this->__('`{addition}`')) . '", apiShowcase: "' . htmlspecialchars($this->__('API Showcase')) . '", apiDebug: "' . htmlspecialchars($this->__('API Debug')) . '", disabledText: "' . htmlspecialchars($this->__('- disabled -')) . '", infoLabel: "' . htmlspecialchars($this->__('Address validation')) . '", infoText: "' . htmlspecialchars($this->__('Fill out your postcode and housenumber to auto-complete your address. You can also manually set your address information.')) . '", manualInputLabel: "' . htmlspecialchars($this->__('Manual input')) . '", manualInputText: "' . htmlspecialchars($this->__('Fill out address information manually')) . '", outputLabel: "' . htmlspecialchars($this->__('Validated address')) . '", postOfficeBoxNotAllowed: "' . htmlspecialchars($this->__('Post office box not allowed.')) . '" } }; //]]> </script>'; return $html; } public function lookupAddress($postcode, $houseNumber, $houseNumberAddition) { if (!Mage::getStoreConfig('postcodenl_api/config/enabled')) { return array('message' => $this->__('Postcode.nl API not enabled.')); } // Basic Configuration $serviceKey = trim(Mage::getStoreConfig('postcodenl_api/config/api_key')); $serviceSecret = trim(Mage::getStoreConfig('postcodenl_api/config/api_secret')); // Development options $serviceUrl = trim(Mage::getStoreConfig('postcodenl_api/development_config/api_url')); if (empty($serviceUrl)) $serviceUrl = self::API_URL; $serviceShowcase = Mage::getStoreConfig('postcodenl_api/development_config/api_showcase'); $serviceDebug = Mage::getStoreConfig('postcodenl_api/development_config/api_debug'); $extensionInfo = $this->_getModuleInfo('PostcodeNl_Api'); $extensionVersion = $extensionInfo ? (string)$extensionInfo->version : 'unknown'; if (!$serviceUrl || !$serviceKey || !$serviceSecret) { return array('message' => $this->__('Postcode.nl API not configured.')); } // Check for SSL support in CURL, if connecting to `https` if (substr($serviceUrl, 0, 8) == 'https://') { $curlVersion = curl_version(); if (!($curlVersion['features'] & CURL_VERSION_SSL)) { return array('message' => $this->__('Cannot connect to Postcode.nl API: Server is missing SSL (https) support for CURL.')); } } $url = $serviceUrl . '/rest/addresses/' . urlencode($postcode). '/'. urlencode($houseNumber) . '/'. urlencode($houseNumberAddition); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::API_TIMEOUT); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_USERPWD, $serviceKey .':'. $serviceSecret); curl_setopt($ch, CURLOPT_USERAGENT, 'PostcodeNl_Api_MagentoPlugin/' . $extensionVersion .' '. $this->_getMagentoVersion()); $jsonResponse = curl_exec($ch); $curlError = curl_error($ch); curl_close($ch); $response = json_decode($jsonResponse, true); $sendResponse = array(); if ($serviceShowcase) $sendResponse['showcaseResponse'] = $response; if ($serviceDebug) { $modules = array(); foreach (Mage::getConfig()->getNode('modules')->children() as $name => $module) { $modules[$name] = array(); foreach ($module as $key => $value) { if (in_array((string)$key, array('active'))) $modules[$name][$key] = (string)$value == 'true' ? true : false; else if (in_array((string)$key, array('codePool', 'version'))) $modules[$name][$key] = (string)$value; } } $sendResponse['debugInfo'] = array( 'requestUrl' => $url, 'rawResponse' => $jsonResponse, 'parsedResponse' => $response, 'curlError' => $curlError, 'configuration' => array( 'url' => $serviceUrl, 'key' => $serviceKey, 'secret' => substr($serviceSecret, 0, 6) .'[hidden]', 'showcase' => $serviceShowcase, 'debug' => $serviceDebug, ), 'magentoVersion' => $this->_getMagentoVersion(), 'extensionVersion' => $extensionVersion, 'modules' => $modules, ); } if (is_array($response) && isset($response['exceptionId'])) { switch ($response['exceptionId']) { case 'PostcodeNl_Controller_Address_InvalidPostcodeException': $sendResponse['message'] = $this->__('Invalid postcode format, use `1234AB` format.'); $sendResponse['messageTarget'] = 'postcode'; break; case 'PostcodeNl_Service_PostcodeAddress_AddressNotFoundException': $sendResponse['message'] = $this->__('Unknown postcode + housenumber combination.'); $sendResponse['messageTarget'] = 'housenumber'; break; case 'PostcodeNl_Controller_Address_InvalidHouseNumberException': $sendResponse['message'] = $this->__('Housenumber format is not valid.'); $sendResponse['messageTarget'] = 'housenumber'; break; default: $sendResponse['message'] = $this->__('Validation error, please use manual input.'); $sendResponse['messageTarget'] = 'housenumber'; break; } } else if (is_array($response) && isset($response['postcode'])) { $sendResponse = array_merge($sendResponse, $response); } else { $sendResponse['message'] = $this->__('Validation unavailable, please use manual input.'); $sendResponse['messageTarget'] = 'housenumber'; } return $sendResponse; } }

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.0000.01518.52
8.3.50.0140.00921.92
8.3.40.0000.01519.10
8.3.30.0030.01020.29
8.3.20.0080.00020.25
8.3.10.0000.00722.15
8.3.00.0040.00422.47
8.2.180.0120.00618.41
8.2.170.0070.00722.96
8.2.160.0110.00420.51
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0060.01226.16
8.2.120.0040.00419.54
8.2.110.0080.00022.08
8.2.100.0070.00719.51
8.2.90.0000.00819.22
8.2.80.0040.00419.50
8.2.70.0050.00317.75
8.2.60.0070.00317.93
8.2.50.0040.00418.07
8.2.40.0050.00319.63
8.2.30.0080.00018.11
8.2.20.0040.00417.80
8.2.10.0060.00317.98
8.2.00.0030.00617.91
8.1.280.0090.00625.92
8.1.270.0040.00424.66
8.1.260.0090.00026.35
8.1.250.0030.00528.09
8.1.240.0040.00423.98
8.1.230.0070.00419.29
8.1.220.0030.00517.74
8.1.210.0000.00818.77
8.1.200.0070.00317.35
8.1.190.0050.00317.53
8.1.180.0040.00420.38
8.1.170.0080.00018.71
8.1.160.0000.00822.31
8.1.150.0000.00718.75
8.1.140.0040.00417.66
8.1.130.0040.00417.92
8.1.120.0000.00817.57
8.1.110.0050.00317.57
8.1.100.0070.00017.60
8.1.90.0040.00417.55
8.1.80.0030.00517.57
8.1.70.0000.00817.54
8.1.60.0030.00617.68
8.1.50.0000.00817.63
8.1.40.0000.00817.63
8.1.30.0040.00417.64
8.1.20.0000.00817.66
8.1.10.0000.00817.70
8.1.00.0070.00317.61
8.0.300.0070.00018.77
8.0.290.0040.00417.41
8.0.280.0000.00718.64
8.0.270.0040.00417.43
8.0.260.0070.00017.07
8.0.250.0000.00717.14
8.0.240.0020.00517.25
8.0.230.0030.00317.20
8.0.220.0050.00217.10
8.0.210.0030.00517.16
8.0.200.0080.00017.17
8.0.190.0040.00417.16
8.0.180.0090.00017.01
8.0.170.0000.00716.99
8.0.160.0000.00717.12
8.0.150.0050.00317.10
8.0.140.0030.00617.03
8.0.130.0000.00613.50
8.0.120.0000.00817.07
8.0.110.0000.00817.07
8.0.100.0040.00417.18
8.0.90.0050.00317.20
8.0.80.0000.01617.09
8.0.70.0000.00817.08
8.0.60.0040.00417.02
8.0.50.0000.00816.96
8.0.30.0080.01117.34
8.0.20.0080.01017.40
8.0.10.0050.00517.15
8.0.00.0110.00916.93
7.4.330.0030.00315.00
7.4.320.0060.00016.60
7.4.300.0030.00716.74
7.4.290.0000.00716.70
7.4.280.0000.00716.69
7.4.270.0030.00316.68
7.4.260.0030.00516.62
7.4.250.0000.00816.61
7.4.240.0060.00116.63
7.4.230.0040.00416.82
7.4.220.0130.01316.55
7.4.210.0100.00416.63
7.4.200.0000.00716.71
7.4.190.0030.00316.58
7.4.160.0090.01516.62
7.4.150.0060.01217.40
7.4.140.0080.01117.86
7.4.130.0130.00816.76
7.4.120.0060.01316.63
7.4.110.0090.00916.50
7.4.100.0060.01216.65
7.4.90.0130.00716.83
7.4.80.0070.01419.39
7.4.70.0130.01016.79
7.4.60.0090.00816.54
7.4.50.0040.00416.58
7.4.40.0090.00622.77
7.4.30.0100.00816.52
7.4.10.0070.01415.26
7.4.00.0090.00815.21
7.3.330.0000.00513.33
7.3.320.0060.00013.54
7.3.310.0040.00416.46
7.3.300.0040.00416.49
7.3.290.0150.00616.40
7.3.280.0090.00816.47
7.3.270.0090.00917.40
7.3.260.0030.01616.49
7.3.250.0070.01316.62
7.3.240.0130.01016.65
7.3.230.0070.01116.45
7.3.210.0140.00316.78
7.3.200.0120.00619.39
7.3.190.0120.00816.73
7.3.180.0090.00916.78
7.3.170.0090.00616.47
7.3.160.0090.00916.45
7.3.130.0130.00614.95
7.3.120.0060.01015.08
7.3.110.0100.00715.20
7.3.100.0070.01014.91
7.3.90.0060.00914.96
7.3.80.0000.01114.97
7.3.70.0080.00014.92
7.3.60.0100.00314.95
7.3.50.0060.00814.85
7.3.40.0040.01114.84
7.3.30.0030.00915.00
7.3.20.0090.00616.27
7.3.10.0000.00916.80
7.3.00.0100.00816.65
7.2.330.0130.00716.68
7.2.320.0110.01116.55
7.2.310.0080.01616.60
7.2.300.0060.01516.55
7.2.290.0130.00316.56
7.2.260.0030.01715.02
7.2.250.0070.01315.16
7.2.240.0090.00314.89
7.2.230.0060.00614.93
7.2.220.0070.01015.14
7.2.210.0060.00814.90
7.2.200.0110.00415.02
7.2.190.0000.00915.11
7.2.180.0100.00014.72
7.2.170.0030.00714.98
7.2.160.0030.01015.03
7.2.150.0080.00616.72
7.2.140.0090.00316.48
7.2.130.0110.00716.80
7.2.120.0130.00716.57
7.2.110.0070.00716.66
7.2.100.0030.00916.88
7.2.90.0130.00316.87
7.2.80.0040.00816.70
7.2.70.0070.00716.89
7.2.60.0060.00716.74
7.2.50.0000.01016.76
7.2.40.0070.00716.98
7.2.30.0060.00316.84
7.2.20.0070.01116.74
7.2.10.0040.00716.57
7.2.00.0060.00817.95
7.1.330.0080.00315.50
7.1.320.0000.01015.73
7.1.310.0000.01415.68
7.1.300.0090.00315.82
7.1.290.0000.00915.80
7.1.280.0000.00815.50
7.1.270.0070.00715.38
7.1.260.0040.00415.88
7.1.250.0040.01115.59
7.1.240.0070.01115.67
7.1.230.0060.00315.79
7.1.220.0060.00615.39
7.1.210.0030.01315.41
7.1.200.0030.01015.56
7.1.190.0100.00315.63
7.1.180.0060.00915.54
7.1.170.0060.00315.31
7.1.160.0000.00915.61
7.1.150.0060.00615.60
7.1.140.0000.00915.73
7.1.130.0090.00315.66
7.1.120.0000.01415.68
7.1.110.0030.00715.54
7.1.100.0050.00516.84
7.1.90.0090.00615.74
7.1.80.0000.01115.43
7.1.70.0050.00816.42
7.1.60.0090.00917.55
7.1.50.0100.00616.30
7.1.40.0000.01515.72
7.1.30.0060.00315.59
7.1.20.0060.00615.34
7.1.10.0040.01115.62
7.1.00.0030.02219.07
7.0.330.0060.00315.30
7.0.320.0120.00315.34
7.0.310.0000.00815.45
7.0.300.0040.00414.95
7.0.290.0120.00014.92
7.0.280.0030.00915.46
7.0.270.0090.00615.49
7.0.260.0030.00715.05
7.0.250.0000.01015.46
7.0.240.0070.01015.28
7.0.230.0120.00315.37
7.0.220.0100.00315.09
7.0.210.0060.00615.37
7.0.200.0000.00915.93
7.0.190.0060.00915.12
7.0.180.0070.00715.43
7.0.170.0000.01414.95
7.0.160.0110.00315.46
7.0.150.0040.00414.93
7.0.140.0030.04118.84
7.0.130.0060.00315.46
7.0.120.0080.00815.47
7.0.110.0150.00015.21
7.0.100.0060.02517.68
7.0.90.0050.03717.62
7.0.80.0040.03117.70
7.0.70.0080.04517.66
7.0.60.0080.04717.68
7.0.50.0050.02817.87
7.0.40.0020.04916.84
7.0.30.0060.03116.58
7.0.20.0070.03816.67
7.0.10.0130.02816.68
7.0.00.0070.03316.70
5.6.400.0030.01014.24
5.6.390.0150.00314.36
5.6.380.0000.01314.30
5.6.370.0000.01113.96
5.6.360.0100.00314.15
5.6.350.0030.00714.46
5.6.340.0040.00414.54
5.6.330.0080.00614.21
5.6.320.0110.00414.07
5.6.310.0070.00714.53
5.6.300.0030.01014.42
5.6.290.0040.00814.19
5.6.280.0050.03817.66
5.6.270.0070.01114.35
5.6.260.0120.00314.37
5.6.250.0030.02617.52
5.6.240.0020.03517.52
5.6.230.0060.02317.44
5.6.220.0070.04917.26
5.6.210.0070.04717.47
5.6.200.0100.04217.67
5.6.190.0090.02917.84
5.6.180.0110.04617.61
5.6.170.0080.04617.72
5.6.160.0080.04217.70
5.6.150.0140.03917.66
5.6.140.0070.04117.66
5.6.130.0080.04117.69
5.6.120.0070.04217.64
5.6.110.0030.04917.76
5.6.100.0030.05017.67
5.6.90.0080.04817.73
5.6.80.0130.03617.43
5.6.70.0060.04517.32
5.6.60.0050.04717.31
5.6.50.0150.02317.34
5.6.40.0090.04117.48
5.6.30.0060.03317.39
5.6.20.0000.04917.35
5.6.10.0050.04717.38
5.6.00.0080.04017.22
5.5.380.0030.02617.24
5.5.370.0040.02517.43
5.5.360.0080.04717.21
5.5.350.0090.04317.13
5.5.340.0050.03017.47
5.5.330.0140.03317.49
5.5.320.0090.03817.55
5.5.310.0100.02317.56
5.5.300.0080.04417.62
5.5.290.0070.04417.65
5.5.280.0090.03617.56
5.5.270.0130.03817.66
5.5.260.0120.02817.48
5.5.250.0080.04217.42
5.5.240.0090.04217.14
5.5.230.0110.04317.06
5.5.220.0080.02516.95
5.5.210.0080.03817.24
5.5.200.0060.04117.02
5.5.190.0050.04817.24
5.5.180.0020.05217.26
5.5.170.0000.01414.22
5.5.160.0120.03917.02
5.5.150.0100.03017.26
5.5.140.0080.02517.24
5.5.130.0030.04817.21
5.5.120.0040.04117.14
5.5.110.0090.03917.20
5.5.100.0070.03217.16
5.5.90.0050.04517.27
5.5.80.0070.02917.09
5.5.70.0080.03017.08
5.5.60.0020.03917.14
5.5.50.0100.04017.08
5.5.40.0100.03817.09
5.5.30.0030.05017.13
5.5.20.0050.02817.22
5.5.10.0030.02517.27
5.5.00.0030.03117.07
5.4.450.0080.04415.12
5.4.440.0050.02815.11
5.4.430.0060.03915.16
5.4.420.0120.03715.17
5.4.410.0080.04015.07
5.4.400.0060.02414.85
5.4.390.0100.03314.97
5.4.380.0070.04214.96
5.4.370.0080.04414.85
5.4.360.0060.04414.93
5.4.350.0050.03914.95
5.4.340.0030.02714.98
5.4.330.0040.00710.93
5.4.320.0050.04315.07
5.4.310.0080.04015.00
5.4.300.0070.03715.05
5.4.290.0030.04014.92
5.4.280.0080.03314.82
5.4.270.0050.04014.89
5.4.260.0050.04314.96
5.4.250.0100.03314.84
5.4.240.0030.02815.08
5.4.230.0030.04014.95
5.4.220.0050.02814.85
5.4.210.0070.04014.98
5.4.200.0080.04114.81
5.4.190.0030.02814.77
5.4.180.0030.03515.05
5.4.170.0050.04215.00
5.4.160.0120.02514.72
5.4.150.0080.03714.70
5.4.140.0030.04413.63
5.4.130.0020.04113.66
5.4.120.0080.03813.62
5.4.110.0090.03313.69
5.4.100.0080.03513.65
5.4.90.0060.03813.49
5.4.80.0040.03713.61
5.4.70.0040.03813.69
5.4.60.0060.04113.60
5.4.50.0120.03013.56
5.4.40.0040.04013.74
5.4.30.0080.02213.61
5.4.20.0030.02813.55
5.4.10.0080.03813.59
5.4.00.0100.03913.29
5.3.290.0050.03912.68
5.3.280.0050.04412.56
5.3.270.0080.03712.47
5.3.260.0070.03312.49
5.3.250.0030.04012.65
5.3.240.0030.04112.52
5.3.230.0010.04812.59
5.3.220.0070.03912.48
5.3.210.0080.03812.52
5.3.200.0030.04012.53
5.3.190.0020.03812.56
5.3.180.0100.03312.65
5.3.170.0050.02412.52
5.3.160.0030.04112.54
5.3.150.0110.03312.70
5.3.140.0030.02812.60
5.3.130.0060.03212.59
5.3.120.0050.04212.60
5.3.110.0060.02512.52
5.3.100.0050.04312.26
5.3.90.0080.03812.38
5.3.80.0110.03012.10
5.3.70.0030.02312.30
5.3.60.0050.03712.28
5.3.50.0100.03512.15
5.3.40.0030.04012.13
5.3.30.0030.04412.06
5.3.20.0090.03312.12
5.3.10.0060.03811.89
5.3.00.0080.03811.94

preferences:
48.31 ms | 401 KiB | 5 Q