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]; } protected function _getConfigBoolString($configKey) { if (Mage::getStoreConfig($configKey)) return 'true'; return 'false'; } /** * Get the html for initializing validation script. * * @return string */ public function getJsinit($getAdminConfig = 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: ' . $this->_getConfigBoolString('postcodenl_api/advanced_config/admin_validation_disabled') . ', useStreet2AsHouseNumber: ' . $this->_getConfigBoolString('postcodenl_api/advanced_config/use_street2_as_housenumber') . ', blockPostOfficeBoxAddresses: '. $this->_getConfigBoolString('postcodenl_api/advanced_config/block_postofficeboxaddresses') . ', neverHideCountry: ' . $this->_getConfigBoolString('postcodenl_api/advanced_config/never_hide_country') . ', showcase: ' . $this->_getConfigBoolString('postcodenl_api/development_config/api_showcase') . ', debug: ' . $this->_getConfigBoolString('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.40.0110.00418.99
8.3.30.0110.00320.45
8.3.20.0050.00320.28
8.3.10.0080.00022.09
8.3.00.0090.00622.44
8.2.170.0120.00322.96
8.2.160.0040.01120.70
8.2.150.0000.00824.18
8.2.140.0060.00324.66
8.2.130.0090.00926.16
8.2.120.0000.00819.54
8.2.110.0110.00020.87
8.2.100.0060.00617.97
8.2.90.0000.00818.00
8.2.80.0070.00417.97
8.2.70.0030.00618.05
8.2.60.0050.00318.16
8.2.50.0030.00518.10
8.2.40.0080.00020.59
8.2.30.0070.00318.18
8.2.20.0040.00417.96
8.2.10.0050.00317.96
8.2.00.0040.00417.84
8.1.270.0080.00024.66
8.1.260.0040.00426.35
8.1.250.0000.00828.09
8.1.240.0100.00320.72
8.1.230.0090.00322.81
8.1.220.0050.00317.80
8.1.210.0000.00818.77
8.1.200.0030.00717.50
8.1.190.0060.00317.47
8.1.180.0040.00418.10
8.1.170.0080.00018.73
8.1.160.0040.00422.34
8.1.150.0040.00418.75
8.1.140.0000.00717.57
8.1.130.0070.00017.86
8.1.120.0040.00417.52
8.1.110.0040.00417.58
8.1.100.0000.00717.57
8.1.90.0000.00717.57
8.1.80.0040.00417.54
8.1.70.0070.00017.46
8.1.60.0080.00017.52
8.1.50.0030.00517.66
8.1.40.0040.00417.64
8.1.30.0040.00417.69
8.1.20.0000.00817.79
8.1.10.0040.00417.72
8.1.00.0030.00717.48
8.0.300.0040.00420.09
8.0.290.0060.00317.00
8.0.280.0000.00818.56
8.0.270.0070.00017.35
8.0.260.0000.00717.06
8.0.250.0040.00417.24
8.0.240.0000.00717.12
8.0.230.0040.00417.11
8.0.220.0040.00417.16
8.0.210.0070.00017.09
8.0.200.0000.00717.19
8.0.190.0030.00617.20
8.0.180.0000.00817.17
8.0.170.0000.00817.02
8.0.160.0000.00717.08
8.0.150.0080.00017.03
8.0.140.0000.00717.11
8.0.130.0030.00313.61
8.0.120.0000.00717.06
8.0.110.0080.00016.95
8.0.100.0040.00417.14
8.0.90.0000.00816.98
8.0.80.0030.01717.14
8.0.70.0080.00016.92
8.0.60.0080.00017.08
8.0.50.0040.00417.11
8.0.30.0130.00517.28
8.0.20.0100.00917.41
8.0.10.0050.00217.06
8.0.00.0090.01016.74
7.4.330.0000.00515.00
7.4.320.0000.00616.73
7.4.300.0040.00416.73
7.4.290.0050.00216.65
7.4.280.0000.00716.53
7.4.270.0000.00716.59
7.4.260.0040.00316.64
7.4.250.0050.00316.73
7.4.240.0040.00416.58
7.4.230.0040.00416.51
7.4.220.0090.00916.65
7.4.210.0070.01016.61
7.4.200.0000.00716.51
7.4.190.0070.00016.59
7.4.160.0100.00616.55
7.4.150.0030.01517.40
7.4.140.0060.01317.86
7.4.130.0110.00716.62
7.4.120.0060.01116.62
7.4.110.0030.01316.69
7.4.100.0070.01116.81
7.4.90.0090.00916.70
7.4.80.0150.00719.39
7.4.70.0080.01516.71
7.4.60.0110.00616.50
7.4.50.0080.00016.61
7.4.40.0030.01522.77
7.4.30.0100.01016.77
7.4.00.0090.00915.14
7.3.330.0030.00313.46
7.3.320.0030.00313.27
7.3.310.0040.00416.45
7.3.300.0080.00016.43
7.3.290.0030.01016.47
7.3.280.0100.00916.47
7.3.270.0130.00317.40
7.3.260.0070.01416.69
7.3.250.0050.01216.64
7.3.240.0100.00716.73
7.3.230.0070.01116.61
7.3.210.0030.01416.52
7.3.200.0110.01119.39
7.3.190.0050.01416.63
7.3.180.0130.00316.63
7.3.170.0100.01016.48
7.3.160.0030.01416.58
7.3.120.0060.01015.14
7.3.110.0120.00615.11
7.3.100.0040.00815.22
7.3.90.0040.01114.96
7.3.80.0070.00714.87
7.3.70.0040.01114.86
7.3.60.0090.00615.08
7.3.50.0070.01014.91
7.3.40.0000.01714.88
7.3.30.0030.01315.02
7.3.20.0060.00916.56
7.3.10.0000.01716.68
7.3.00.0030.01016.66
7.2.330.0130.00616.56
7.2.320.0080.01116.51
7.2.310.0170.00816.54
7.2.300.0030.01616.80
7.2.290.0120.01216.53
7.2.240.0030.00614.89
7.2.230.0040.01115.17
7.2.220.0090.00315.11
7.2.210.0050.00515.11
7.2.200.0100.00715.10
7.2.190.0090.00614.96
7.2.180.0040.01415.11
7.2.170.0030.01415.21
7.2.160.0030.01015.01
7.2.150.0070.00316.64
7.2.140.0070.00716.63
7.2.130.0000.01716.65
7.2.120.0030.00916.93
7.2.110.0000.01016.74
7.2.100.0030.01316.60
7.2.90.0000.01016.58
7.2.80.0040.00816.66
7.2.70.0120.00316.85
7.2.60.0040.01016.96
7.2.50.0100.00316.69
7.2.40.0040.00416.57
7.2.30.0040.00816.74
7.2.20.0060.00316.82
7.2.10.0080.00316.75
7.2.00.0040.00617.95
7.1.330.0030.01015.81
7.1.320.0120.00615.71
7.1.310.0140.00015.55
7.1.300.0040.01115.50
7.1.290.0090.00615.51
7.1.280.0070.00315.72
7.1.270.0050.00515.78
7.1.260.0040.00815.73
7.1.250.0040.01115.55
7.1.200.0090.00615.46
7.1.100.0090.00618.08
7.1.70.0040.00416.85
7.1.60.0110.01419.43
7.1.50.0060.01316.76
7.1.00.0100.05322.38
7.0.200.0060.00616.70
7.0.140.0000.07722.02
7.0.100.0270.05320.07
7.0.90.0270.05320.04
7.0.80.0370.08320.15
7.0.70.0330.04720.05
7.0.60.0370.06719.98
7.0.50.0300.08720.48
7.0.40.0030.05720.16
7.0.30.0100.06720.15
7.0.20.0030.08720.05
7.0.10.0070.08320.06
7.0.00.0070.08320.14
5.6.280.0030.07020.95
5.6.250.0070.04720.82
5.6.240.0000.09020.70
5.6.230.0100.07720.76
5.6.220.0070.08320.57
5.6.210.0030.09020.74
5.6.200.0130.08721.14
5.6.190.0130.07721.27
5.6.180.0130.04321.13
5.6.170.0130.07021.12
5.6.160.0130.07321.16
5.6.150.0100.08021.13
5.6.140.0100.06721.22
5.6.130.0070.08321.23
5.6.120.0000.08321.20
5.6.110.0100.08021.19
5.6.100.0070.07021.18
5.6.90.0070.07721.07
5.6.80.0070.05720.55
5.6.70.0000.04320.50
5.6.60.0070.03720.48
5.6.50.0070.04020.55
5.6.40.0130.03020.41
5.6.30.0030.06320.37
5.6.20.0070.07720.47
5.6.10.0070.08320.50
5.6.00.0170.06720.38
5.5.380.0170.07020.66
5.5.370.0170.06720.43
5.5.360.0070.07320.46
5.5.350.0030.08720.53
5.5.340.0100.04720.70
5.5.330.0100.06321.02
5.5.320.0070.08020.89
5.5.310.0070.07720.96
5.5.300.0070.08021.00
5.5.290.0100.04720.97
5.5.280.0030.08020.90
5.5.270.0070.07720.85
5.5.260.0130.06320.96
5.5.250.0130.07720.74
5.5.240.0030.04020.28
5.5.230.0030.04320.33
5.5.220.0100.03320.27
5.5.210.0030.04720.09
5.5.200.0000.04320.31
5.5.190.0030.04320.31
5.5.180.0100.03320.18
5.5.160.0030.07320.37
5.5.150.0030.04720.27
5.5.140.0100.03720.35
5.5.130.0030.08320.21
5.5.120.0030.04720.24
5.5.110.0100.03720.21
5.5.100.0100.03720.11
5.5.90.0070.04320.15
5.5.80.0000.04320.25
5.5.70.0070.04020.21
5.5.60.0030.03720.13
5.5.50.0030.03720.16
5.5.40.0070.03320.18
5.5.30.0000.04320.23
5.5.20.0030.05020.20
5.5.10.0030.03320.15
5.5.00.0030.04020.13
5.4.450.0000.09019.39
5.4.440.0170.06719.25
5.4.430.0100.07319.48
5.4.420.0100.06019.30
5.4.410.0100.05719.49
5.4.400.0030.04319.07
5.4.390.0070.04319.16
5.4.380.0070.03718.94
5.4.370.0030.04019.13
5.4.360.0000.04019.16
5.4.350.0070.04019.21
5.4.340.0100.07318.98
5.4.320.0000.04019.24
5.4.310.0000.08319.09
5.4.300.0100.05319.13
5.4.290.0130.03019.06
5.4.280.0100.03319.14
5.4.270.0070.03719.06
5.4.260.0000.04019.05
5.4.250.0030.03719.09
5.4.240.0030.03719.09
5.4.230.0030.04019.20
5.4.220.0070.03718.98
5.4.210.0000.04019.09
5.4.200.0070.03319.13
5.4.190.0100.03018.91
5.4.180.0030.03019.22
5.4.170.0100.03019.05
5.4.160.0070.07318.85
5.4.150.0030.03718.90
5.4.140.0000.04016.50
5.4.130.0070.04016.48
5.4.120.0000.03716.48
5.4.110.0000.04016.48
5.4.100.0000.03716.57
5.4.90.0070.03316.46
5.4.80.0000.03716.49
5.4.70.0030.03316.49
5.4.60.0070.04316.52
5.4.50.0100.04016.40
5.4.40.0030.04716.37
5.4.30.0070.03316.50
5.4.20.0070.06716.32
5.4.10.0170.06016.32
5.4.00.0170.06315.93
5.3.290.0100.07314.90
5.3.280.0030.03714.74
5.3.270.0030.04314.68
5.3.260.0070.03314.79
5.3.250.0000.04014.65
5.3.240.0000.04014.70
5.3.230.0070.03714.70
5.3.220.0000.04314.82
5.3.210.0000.04014.66
5.3.200.0070.03314.80
5.3.190.0030.04714.74
5.3.180.0100.03014.63
5.3.170.0030.06314.74
5.3.160.0000.04014.74
5.3.150.0000.04014.81
5.3.140.0070.03714.74
5.3.130.0130.05314.68
5.3.120.0070.07014.70
5.3.110.0070.05014.68
5.3.100.0070.07714.22
5.3.90.0070.07014.20
5.3.80.0100.06014.13
5.3.70.0030.06314.27
5.3.60.0070.03314.09
5.3.50.0000.07714.05
5.3.40.0030.05314.11
5.3.30.0100.07014.01
5.3.20.0030.07713.84
5.3.10.0070.05013.84
5.3.00.0100.07013.64

preferences:
31.75 ms | 400 KiB | 5 Q