3v4l.org

run code in 300+ PHP versions simultaneously
<?php class PostcodeNl_Api_Helper_Data //xtends 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.60.0140.00718.18
8.3.50.0130.01021.98
8.3.40.0130.01018.84
8.3.30.0070.00720.42
8.3.20.0050.00320.47
8.3.10.0040.00422.04
8.3.00.0040.01122.43
8.2.180.0100.00716.75
8.2.170.0090.00622.96
8.2.160.0110.00420.56
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0040.01426.16
8.2.120.0000.00819.54
8.2.110.0030.00721.13
8.2.100.0090.00317.93
8.2.90.0060.00319.17
8.2.80.0000.00817.97
8.2.70.0030.00517.63
8.2.60.0080.00019.16
8.2.50.0060.00318.10
8.2.40.0050.00319.48
8.2.30.0030.00617.99
8.2.20.0000.00817.73
8.2.10.0040.00417.74
8.2.00.0060.00317.64
8.1.280.0150.00325.92
8.1.270.0080.00024.66
8.1.260.0070.00026.35
8.1.250.0040.00428.09
8.1.240.0060.00319.41
8.1.230.0040.00717.83
8.1.220.0000.00817.78
8.1.210.0050.00518.77
8.1.200.0000.00917.35
8.1.190.0000.00817.22
8.1.180.0040.00418.10
8.1.170.0080.00018.63
8.1.160.0050.00322.25
8.1.150.0000.00918.74
8.1.140.0040.00417.56
8.1.130.0080.00017.94
8.1.120.0070.00017.60
8.1.110.0040.00417.46
8.1.100.0040.00417.56
8.1.90.0030.00517.59
8.1.80.0020.00517.61
8.1.70.0030.00317.57
8.1.60.0090.00017.60
8.1.50.0000.00917.64
8.1.40.0040.00417.60
8.1.30.0060.00317.57
8.1.20.0030.00517.68
8.1.10.0030.00517.59
8.1.00.0040.00817.55
8.0.300.0040.00418.77
8.0.290.0030.00616.75
8.0.280.0070.00018.41
8.0.270.0000.00717.31
8.0.260.0030.00316.94
8.0.250.0020.00517.01
8.0.240.0040.00417.05
8.0.230.0030.00316.87
8.0.220.0030.00416.97
8.0.210.0000.00716.97
8.0.200.0040.00416.87
8.0.190.0020.00516.90
8.0.180.0040.00416.95
8.0.170.0070.00016.90
8.0.160.0040.00416.80
8.0.150.0030.00616.96
8.0.140.0040.00416.93
8.0.130.0000.00613.40
8.0.120.0000.00816.82
8.0.110.0040.00416.77
8.0.100.0040.00416.93
8.0.90.0030.00517.02
8.0.80.0120.00316.99
8.0.70.0000.00816.97
8.0.60.0080.00016.95
8.0.50.0040.00416.89
8.0.30.0100.00817.24
8.0.20.0080.01117.40
8.0.10.0040.00417.06
8.0.00.0090.01116.90
7.4.330.0030.00315.00
7.4.320.0030.00316.57
7.4.300.0100.00016.68
7.4.290.0070.00016.67
7.4.280.0030.00316.47
7.4.270.0070.00016.57
7.4.260.0020.00516.67
7.4.250.0040.00416.43
7.4.240.0000.00716.59
7.4.230.0040.00416.31
7.4.220.0130.01316.59
7.4.210.0110.00416.68
7.4.200.0000.00716.46
7.4.190.0040.00416.61
7.4.160.0080.01216.64
7.4.150.0140.00417.40
7.4.140.0100.00817.86
7.4.130.0100.00916.59
7.4.120.0130.00516.61
7.4.110.0090.00916.46
7.4.100.0070.01116.55
7.4.90.0100.01016.76
7.4.80.0040.01319.39
7.4.70.0060.01216.54
7.4.60.0040.01316.56
7.4.50.0030.00616.62
7.4.40.0090.00322.77
7.4.30.0070.01016.59
7.4.00.0110.00415.06
7.3.330.0030.00313.35
7.3.320.0050.00013.43
7.3.310.0040.00416.35
7.3.300.0000.00716.21
7.3.290.0070.00716.30
7.3.280.0090.00916.31
7.3.270.0070.01017.40
7.3.260.0030.01516.42
7.3.250.0080.01016.51
7.3.240.0100.00716.36
7.3.230.0070.01016.42
7.3.210.0120.00616.31
7.3.200.0070.01519.39
7.3.190.0140.01016.62
7.3.180.0100.01016.71
7.3.170.0070.01416.27
7.3.160.0080.00816.37
7.3.120.0070.00714.58
7.2.330.0060.01316.59
7.2.320.0160.00916.37
7.2.310.0100.01516.77
7.2.300.0150.00316.56
7.2.290.0140.00316.53
7.2.00.0000.01419.17
7.1.100.0170.00318.04
7.1.70.0000.00817.02
7.1.60.0070.01319.43
7.1.50.0040.00716.57
7.1.00.0000.04722.55
7.0.200.0040.00416.69
7.0.140.0000.07721.99
7.0.120.0030.07322.03
7.0.110.0070.07322.05
7.0.100.0030.06722.14
7.0.90.0000.08022.07
7.0.80.0000.07322.04
7.0.70.0030.06721.98
7.0.60.0130.06322.07
7.0.50.0070.07022.01
7.0.40.0030.06722.09
7.0.30.0070.06322.10
7.0.20.0000.07322.08
7.0.10.0030.07322.06
7.0.00.0030.07022.12
5.6.280.0030.07320.95
5.6.260.0000.07320.97
5.6.250.0030.07320.96
5.6.240.0000.08021.22
5.6.230.0030.07721.16
5.6.220.0070.07321.20
5.6.210.0070.07021.07
5.6.200.0030.07721.16
5.6.190.0000.07720.83
5.6.180.0030.07321.13
5.6.170.0030.07321.10
5.6.160.0070.07020.84
5.6.150.0070.07021.02
5.6.140.0130.06721.09
5.6.130.0070.06721.17
5.6.120.0100.07021.02
5.6.110.0000.08021.02
5.6.100.0030.08021.12
5.6.90.0000.07721.01
5.6.80.0000.07020.31
5.6.70.0030.06720.39
5.6.60.0000.07720.55
5.6.50.0100.06320.27
5.6.40.0030.06720.39
5.6.30.0000.06720.49
5.6.20.0030.05720.48
5.6.10.0030.07020.29
5.6.00.0030.07020.30
5.5.380.0000.07317.63
5.5.370.0070.07017.64
5.5.360.0030.07317.71
5.5.350.0000.07017.63
5.5.340.0070.06718.15
5.5.330.0030.06018.17
5.5.320.0070.06718.14
5.5.310.0000.07018.03
5.5.300.0030.07018.14
5.5.290.0000.08018.28
5.5.280.0070.07018.02
5.5.270.0030.07318.22
5.5.260.0000.06318.22
5.5.250.0000.07318.02
5.5.240.0070.05317.53
5.5.230.0030.06317.51
5.5.220.0000.07017.38
5.5.210.0000.07017.48
5.5.200.0000.07317.62
5.5.190.0000.05717.29
5.5.180.0030.06717.45
5.5.160.0100.06017.41
5.5.150.0030.07017.37
5.5.140.0030.07017.48
5.5.130.0070.06717.51
5.5.120.0070.06017.48
5.5.110.0030.06317.29
5.5.100.0030.07017.27
5.5.90.0000.07017.45
5.5.80.0030.06717.41
5.5.70.0030.06717.48
5.5.60.0000.07017.47
5.5.50.0000.07017.38
5.5.40.0000.07017.44
5.5.30.0000.07017.50
5.5.20.0000.07317.52
5.5.10.0030.06717.37
5.5.00.0030.05317.49
5.4.450.0070.07019.38
5.4.440.0000.07719.29
5.4.430.0070.06719.32
5.4.420.0030.06319.54
5.4.410.0000.05719.20
5.4.400.0000.07019.05
5.4.390.0100.06319.09
5.4.380.0070.06019.02
5.4.370.0030.07019.37
5.4.360.0000.07319.01
5.4.350.0030.06019.03
5.4.340.0030.06019.02
5.4.320.0070.07019.24
5.4.310.0030.06719.14
5.4.300.0030.06719.00
5.4.290.0030.06719.13
5.4.280.0070.06719.05
5.4.270.0100.05319.15
5.4.260.0070.06319.36
5.4.250.0000.07019.22
5.4.240.0030.06319.17
5.4.230.0000.07019.15
5.4.220.0030.07019.01
5.4.210.0030.06718.96
5.4.200.0000.06719.00
5.4.190.0030.07019.15
5.4.180.0000.07019.00
5.4.170.0000.05718.99
5.4.160.0000.07019.04
5.4.150.0100.06319.19
5.4.140.0000.07016.50
5.4.130.0030.06316.63
5.4.120.0000.06716.59
5.4.110.0000.07016.44
5.4.100.0000.06716.59
5.4.90.0070.06016.50
5.4.80.0070.05716.50
5.4.70.0030.06316.49
5.4.60.0030.06316.46
5.4.50.0030.06316.57
5.4.40.0030.06316.46
5.4.30.0030.06016.55
5.4.20.0030.06016.34
5.4.10.0070.06316.48
5.4.00.0070.06015.87
5.3.290.0030.07014.81
5.3.280.0000.06714.72
5.3.270.0030.06714.73
5.3.260.0030.07014.68
5.3.250.0070.06314.84
5.3.240.0000.06014.68
5.3.230.0030.06714.57
5.3.220.0000.07014.82
5.3.210.0000.07014.70
5.3.200.0070.06314.81
5.3.190.0030.06314.90
5.3.180.0070.05314.63
5.3.170.0000.06314.75
5.3.160.0100.06014.65
5.3.150.0070.05714.67
5.3.140.0000.07014.89
5.3.130.0000.07314.69
5.3.120.0030.06014.65
5.3.110.0030.07014.62
5.3.100.0000.06714.18
5.3.90.0030.05714.13
5.3.80.0070.06314.35
5.3.70.0030.06314.20
5.3.60.0030.05714.09
5.3.50.0070.05314.10
5.3.40.0030.06314.14
5.3.30.0000.06714.02
5.3.20.0070.06013.84
5.3.10.0030.05313.84
5.3.00.0030.06313.72

preferences:
42.18 ms | 401 KiB | 5 Q