3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Cache { public static function has( $name ){ return false; } public static function get( $name ){ return null; } public static function put( $name, $value, $time = 1440 ){ return true; } } class Collivery { protected $token; protected $client; protected $config; protected $errors = array(); protected $check_cache = 2; protected $default_address_id; protected $client_id; protected $user_id; /** * Setup class with basic Config * * @param Array $config Configuration Array */ function __construct( array $config = array() ) { $this->config = (object) array( 'app_name' => 'Default App Name', // Application Name 'app_version' => '0.0.1', // Application Version 'app_host' => '', // Framework/CMS name and version, eg 'Wordpress 3.8.1 WooCommerce 2.0.20' / 'Joomla! 2.5.17 VirtueMart 2.0.26d' 'app_url' => '', // URL your site is hosted on 'user_email' => 'demo@collivery.co.za', 'user_password' => 'demo', 'demo' => false, ); foreach ( $config as $key => $value ) { $this->config->$key = $value; } if ( $this->config->demo ){ $this->config->user_email = 'demo@collivery.co.za'; $this->config->user_password = 'demo'; } $this->authenticate(); } /** * Setup the Soap Object * * @return SoapClient MDS Collivery Soap Client */ protected function init () { if ( ! $this->client ){ try { $this->client = new SoapClient( // Setup the soap client 'http://www.collivery.co.za/wsdl/v2', // URL to WSDL File array( 'cache_wsdl' => WSDL_CACHE_NONE ) // Don't cache the WSDL file ); } catch (SoapFault $e) { $this->catchSoapFault( $e ); return false; } } return true; } /** * Checks if the Soap Client has been set, and returns it. * * @return SoapClient Webserver Soap Client */ protected function client() { if ( ! $this->client ) { $this->init(); } if ( ! $this->token ) { $this->authenticate(); } return $this->client; } /** * Authenticate and set the token * * @return string */ protected function authenticate() { if ( ( $this->check_cache == 2 ) && Cache::has('collivery.auth') ) { $authenticate = Cache::get('collivery.auth'); $this->default_address_id = $authenticate['default_address_id']; $this->client_id = $authenticate['client_id']; $this->user_id = $authenticate['user_id']; $this->token = $authenticate['token']; return true; } else { if ( ! $this->init() ) return false; $user_email = $this->config->user_email; $user_password = $this->config->user_password; try { $authenticate = $this->client->authenticate($user_email, $user_password, $this->token, array( 'name' => $this->config->app_name . ' mds/collivery/class', 'version' => $this->config->app_version, 'host' => $this->config->app_host, 'url' => $this->config->app_url, 'lang' => 'PHP '. phpversion(), )); } catch (SoapFault $e) { $this->catchSoapFault( $e ); return false; } if ( is_array( $authenticate ) && isset( $authenticate['token'] ) ){ if ( $this->check_cache != 0 ) Cache::put( 'collivery.auth', $authenticate, 50 ); $this->default_address_id = $authenticate['default_address_id']; $this->client_id = $authenticate['client_id']; $this->user_id = $authenticate['user_id']; $this->token = $authenticate['token']; return true; } else { if ( isset( $result['error_id'] ) ) $this->setError( $result['error_id'], $result['error'] ); else $this->setError( 'result_unexpected', 'No address_id returned.' ); return false; } } } /** * Returns a list of towns and their ID's for creating new addresses. * Town can be filtered by country of province (ZAF Only). * * @param string $country Filter towns by Country * @param string $province Filter towns by South African Provinces * @return array List of towns and their ID's */ public function getTowns( $country = "ZAF", $province = null ) { if ( ( $this->check_cache == 2 ) && is_null( $province ) && Cache::has( 'collivery.towns.'. $country ) ) { return Cache::get( 'collivery.towns.'.$country ); } elseif ( ( $this->check_cache == 2 ) && ! is_null( $province ) && Cache::has( 'collivery.towns.'. $country .'.'. $province ) ) { return Cache::get( 'collivery.towns.'.$country.'.'.$province ); } else { try { $result = $this->client()->get_towns( $this->token, $country, $province ); } catch (SoapFault $e) { $this->catchSoapFault( $e ); return false; } if ( isset( $result['towns'] ) ) { if ( is_null( $province ) ) { if ( $this->check_cache != 0 ) Cache::put( 'collivery.towns.'. $country, $result['towns'], 60*24 ); } else { if ( $this->check_cache != 0 ) Cache::put( 'collivery.towns.'. $country .'.'. $province, $result['towns'], 60*24 ); } return $result['towns']; } else { if ( isset( $result['error_id'] ) ) $this->setError( $result['error_id'], $result['error'] ); else $this->setError( 'result_unexpected', 'No address_id returned.' ); return false; } } } /** * Allows you to search for town and suburb names starting with the given string. * The minimum string length to search is two characters. * Returns a list of towns, suburbs, and the towns the suburbs belong to with their ID's for creating new addresses. * The idea is that this could be used in an auto complete function. * * @param string $name Start of town/suburb name * @return array List of towns and their ID's */ function searchTowns( $name ) { if ( strlen( $name ) < 2 ) { return $this->get_towns(); } elseif ( ( $this->check_cache == 2 ) && Cache::has( 'collivery.search_towns.'. $name ) ) { return Cache::get( 'collivery.search_towns.'. $name ); } else { try { $result = $this->client()->search_towns( $name, $this->token ); } catch (SoapFault $e) { $this->catchSoapFault( $e ); return false; } if ( isset( $result ) ) { if ( $this->check_cache != 0 ) Cache::put( 'collivery.search_towns.'. $name, $result, 60*24 ); return $result; } else { if ( isset( $result['error_id'] ) ) $this->setError( $result['error_id'], $result['error'] ); else $this->setError( 'result_unexpected', 'No address_id returned.' ); return false; } } } /** * Returns all the suburbs of a town. * * @param int $town_id ID of the Town to return suburbs for * @return array */ public function getSuburbs( $town_id ) { if ( ( $this->check_cache == 2 ) && Cache::has( 'collivery.suburbs.'. $town_id ) ) { return Cache::get( 'collivery.suburbs.'. $town_id ); } else { try { $result = $this->client()->get_suburbs( $town_id, $this->token ); } catch (SoapFault $e) { $this->catchSoapFault( $e ); return false; } if ( isset( $result['suburbs'] ) ) { if ( $this->check_cache != 0 ) Cache::put( 'collivery.suburbs.'. $town_id, $result['suburbs'], 60*24*7 ); return $result['suburbs']; } else { if ( isset( $result['error_id'] ) ) $this->setError( $result['error_id'], $result['error'] ); else $this->setError( 'result_unexpected', 'No address_id returned.' ); return false; } } } /** * Returns the type of Address Locations. * Certain location type incur a surcharge due to time spent during * delivery. * * @return array */ public function getLocationTypes() { if ( ( $this->check_cache == 2 ) && Cache::has( 'collivery.location_types' ) ) { return Cache::get( 'collivery.location_types' ); } else { try { $result = $this->client()->get_location_types( $this->token ); } catch (SoapFault $e) { $this->catchSoapFault( $e ); return false; } if ( isset( $result['results'] ) ) { if ( $this->check_cache != 0 ) Cache::put( 'collivery.location_types', $result['results'], 60*24*7 ); return $result['results']; } else { if ( isset( $result['error_id'] ) ) $this->setError( $result['error_id'], $result['error'] ); else $this->setError( 'result_unexpected', 'No address_id returned.' ); return false; } } } /** * Returns the available Collivery services types. * * @return array */ public function getServices() { if ( ( $this->check_cache == 2 ) && Cache::has( 'collivery.services' ) ) { return Cache::get( 'collivery.services' ); } else { try { $result = $this->client()->get_services( $this->token ); } catch (SoapFault $e) { $this->catchSoapFault( $e ); return false; } if ( isset( $result['results'] ) ) { if ( $this->check_cache != 0 ) Cache::put( 'collivery.services', $result['results'], 60*24*7 ); return $result['results']; } else { if ( isset( $result['error_id'] ) ) $this->setError( $result['error_id'], $result['error'] ); else $this->setError( 'result_unexpected', 'No address_id returned.' ); return false; } } } /** * Returns the available Parcel Type ID and value array for use in adding a collivery. * * @return array Parcel Types */ public function getParcelTypes() { if ( ( $this->check_cache == 2 ) && Cache::has( 'collivery.parcel_types' ) ) { return Cache::get( 'collivery.parcel_types' ); } else { try { $result = $this->client()->get_parcel_types( $this->token ); } catch (SoapFault $e) { $this->catchSoapFault( $e ); return false; } if ( is_array( $result ) ) { if ( $this->check_cache != 0 ) Cache::put( 'collivery.parcel_types', $result, 60*24*7 ); return $result; } else { if ( isset( $result['error_id'] ) ) $this->setError( $result['error_id'], $result['error'] ); else $this->setError( 'result_unexpected', 'No address_id returned.' ); return false; } } } /** * Returns the available Parcel Type ID and value array for use in adding a collivery. * * @param int $address_id The ID of the address you wish to retrieve. * @return array Address */ public function getAddress( $address_id ) { if ( ( $this->check_cache == 2 ) && Cache::has( 'collivery.address.'. $this->client_id .'.'. $address_id ) ) { return Cache::get( 'collivery.address.'. $this->client_id .'.'. $address_id ); } else { try { $result = $this->client()->get_address( $address_id, $this->token ); } catch (SoapFault $e) { $this->catchSoapFault( $e ); return false; } if ( isset( $result['address'] ) ) { if ( $this->check_cache != 0 ) Cache::put( 'collivery.address.'. $this->client_id .'.'. $address_id, $result['address'], 60*24 ); return $result['address']; } else { if ( isset( $result['error_id'] ) ) $this->setError( $result['error_id'], $result['error'] ); else $this->setError( 'result_unexpected', 'No address_id returned.' ); return false; } } } /** * Returns all the addresses belonging to a client. * * @param array $filter Filter Addresses * @return array */ public function getAddresses( array $filter = array() ) { if ( ( $this->check_cache == 2 ) && empty( $filter ) && Cache::has( 'collivery.addresses.'. $this->client_id ) ) { return Cache::get( 'collivery.addresses.'. $this->client_id ); } else { try { $result = $this->client()->get_addresses( $this->token, $filter ); } catch (SoapFault $e) { $this->catchSoapFault( $e ); return false; } if ( isset( $result['addresses'] ) ) { if ( $this->check_cache != 0 ) Cache::put( 'collivery.addresses.'. $this->client_id, $result['addresses'], 60*24 ); return $result['addresses']; } else { if ( isset( $result['error_id'] ) ) $this->setError( $result['error_id'], $result['error'] ); else $this->setError( 'result_unexpected', 'No address_id returned.' ); return false; } } } /** * Handle error messages in SoapFault * * @param SoapFault $e SoapFault Object */ protected function catchSoapFault( $e ) { $this->setError( $e->faultcode, $e->faultstring ); } /** * Add a new error * * @param string $id Error ID * @param string $text Error text */ protected function setError( $id, $text ) { $this->errors[ $id ] = $text; } /** * Retrieve errors */ public function getErrors() { return $this->errors; } /** * Check if this instance has an error */ public function hasErrors() { return !empty($this->errors); } /** * Clears all the Errors */ public function clearErrors() { $this->errors = array(); } /** * Disable Cached completely and retrieve data directly from the webservice */ public function disableCache() { $this->check_cache = 0; } /** * Ignore Cached data and retrieve data directly from the webservice * Save returned data to Cache */ public function ignoreCache() { $this->check_cache = 1; } /** * Check if cache exists before querying the webservice * If webservice was queried, save returned data to Cache */ public function enableCache() { $this->check_cache = 2; } } $col = new Collivery; print_r( $col->getErrors() );

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.3.10.0070.01116.58
7.3.00.0040.01216.61
7.2.130.0100.00816.79
7.2.120.0080.00916.94
7.2.110.0080.01316.78
7.2.100.0060.01016.82
7.2.90.0090.00716.78
7.2.80.0040.00816.88
7.2.70.0070.01016.84
7.2.60.0100.00916.86
7.2.50.0120.00416.74
7.2.40.0080.00916.83
7.2.30.0070.00916.63
7.2.20.0120.00616.74
7.2.10.0090.00616.75
7.2.00.0070.00917.45
7.1.250.0060.00515.54
7.1.240.0070.00815.50
7.1.230.0020.01315.69
7.1.220.0070.00515.46
7.1.210.0070.01015.66
7.1.200.0090.00315.82
7.1.190.0120.00315.51
7.1.180.0080.00815.88
7.1.170.0040.00915.50
7.1.160.0050.00615.65
7.1.150.0090.00515.54
7.1.140.0040.00915.47
7.1.130.0050.00515.59
7.1.120.0110.00615.64
7.1.110.0030.00615.73
7.1.100.0100.00816.50
7.1.90.0020.01115.77
7.1.80.0040.00915.73
7.1.70.0050.00816.13
7.1.60.0100.00816.88
7.1.50.0010.01216.02
7.1.40.0050.00715.66
7.1.30.0070.00415.48
7.1.20.0050.00615.71
7.1.10.0060.01115.67
7.1.00.0070.01617.68
7.0.330.0040.00715.33
7.0.320.0020.01115.31
7.0.310.0080.00615.30
7.0.300.0040.01215.20
7.0.290.0080.00615.42
7.0.280.0060.00715.28
7.0.270.0030.00815.32
7.0.260.0020.01015.19
7.0.250.0030.01015.28
7.0.240.0070.00415.37
7.0.230.0050.00815.40
7.0.220.0050.00915.28
7.0.210.0040.00715.37
7.0.200.0060.00815.84
7.0.190.0070.01015.28
7.0.180.0000.01015.28
7.0.170.0070.00715.29
7.0.160.0050.00715.33
7.0.150.0020.01015.44
7.0.140.0070.02517.57
7.0.130.0050.00715.29
7.0.120.0060.00515.32
7.0.110.0080.03516.96
7.0.100.0070.01716.96
7.0.90.0060.02117.00
7.0.80.0080.01717.07
7.0.70.0080.01917.03
7.0.60.0090.02116.94
7.0.50.0060.02017.13
7.0.40.0100.01715.58
7.0.30.0070.02015.72
7.0.20.0040.02115.65
7.0.10.0070.01715.50
7.0.00.0080.02215.59
5.6.380.0060.00714.41
5.6.370.0030.01114.50
5.6.360.0030.00814.27
5.6.350.0050.00814.40
5.6.340.0060.01114.26
5.6.330.0060.00614.19
5.6.320.0080.00814.31
5.6.310.0050.00814.23
5.6.300.0080.00514.54
5.6.290.0100.00714.37
5.6.280.0060.02716.49
5.6.270.0110.00314.23
5.6.260.0050.03316.39
5.6.250.0060.02216.57
5.6.240.0000.02516.38
5.6.230.0080.01816.36
5.6.220.0060.02416.47
5.6.210.0030.01716.50
5.6.200.0040.01816.59
5.6.190.0040.02716.60
5.6.180.0050.01916.61
5.6.170.0080.01616.72
5.6.160.0100.01616.77
5.6.150.0100.01816.66
5.6.140.0050.02416.60
5.6.130.0020.02116.54
5.6.120.0040.02016.56
5.6.110.0020.02416.62
5.6.100.0070.02216.57
5.6.90.0050.01916.48
5.6.80.0050.01716.29
5.6.70.0050.02416.42
5.6.60.0070.02916.21
5.6.50.0070.02316.46
5.6.40.0120.02816.36
5.6.30.0080.02016.32
5.6.20.0080.03016.33
5.6.10.0070.03016.27
5.6.00.0090.02116.37
5.5.380.0050.02114.19
5.5.370.0020.02114.22
5.5.360.0010.02014.47
5.5.350.0030.02414.27
5.5.340.0060.01614.41
5.5.330.0110.02714.25
5.5.320.0090.01914.30
5.5.310.0070.01614.41
5.5.300.0070.01614.62
5.5.290.0040.02014.47
5.5.280.0060.01914.40
5.5.270.0050.01814.36
5.5.260.0090.02014.53
5.5.250.0050.01614.44
5.5.240.0070.01714.22
5.5.230.0060.01514.03
5.5.220.0060.03014.13
5.5.210.0070.02614.20
5.5.200.0080.03014.17
5.5.190.0050.03014.15
5.5.180.0050.03214.24
5.5.170.0030.00811.18
5.5.160.0050.02914.29
5.5.150.0100.02814.23
5.5.140.0030.03514.19
5.5.130.0050.03114.32
5.5.120.0060.03114.29
5.5.110.0060.02914.32
5.5.100.0040.02914.30
5.5.90.0090.02114.23
5.5.80.0060.01814.07
5.5.70.0020.02614.09
5.5.60.0090.02614.17
5.5.50.0050.02914.13
5.5.40.0020.03514.22
5.5.30.0060.02713.96
5.5.20.0070.02914.22
5.5.10.0050.03014.09
5.5.00.0050.02914.06
5.4.450.0010.01913.89
5.4.440.0080.02913.89
5.4.430.0030.01813.92
5.4.420.0060.02913.65
5.4.410.0040.01713.73
5.4.400.0030.02013.77
5.4.390.0040.03013.67
5.4.380.0050.01913.49
5.4.370.0070.01413.82
5.4.360.0040.02613.71
5.4.350.0060.02813.74
5.4.340.0040.03313.81
5.4.330.0030.00711.17
5.4.320.0030.03213.74
5.4.310.0090.02713.72
5.4.300.0060.02813.76
5.4.290.0070.02213.75
5.4.280.0020.03013.79
5.4.270.0030.03013.59
5.4.260.0020.03013.74
5.4.250.0030.03113.89
5.4.240.0070.02513.77
5.4.230.0010.03213.68
5.4.220.0090.02413.81
5.4.210.0100.01613.51
5.4.200.0050.03113.63
5.4.190.0080.02013.66
5.4.180.0080.02513.74
5.4.170.0090.02213.62
5.4.160.0040.02113.74
5.4.150.0090.02813.61
5.4.140.0030.02912.92
5.4.130.0080.02712.76
5.4.120.0070.02712.79
5.4.110.0060.01512.76
5.4.100.0050.02912.92
5.4.90.0030.02712.73
5.4.80.0090.02512.93
5.4.70.0010.03012.90
5.4.60.0050.03012.97
5.4.50.0080.02412.95
5.4.40.0060.02012.91
5.4.30.0150.02212.90
5.4.20.0070.01912.93
5.4.10.0090.02412.89
5.4.00.0060.02912.67
5.3.290.0070.02712.45
5.3.280.0010.02712.18
5.3.270.0040.03212.36
5.3.260.0080.02812.29
5.3.250.0050.02912.36
5.3.240.0050.01912.29
5.3.230.0080.02712.27
5.3.220.0050.03112.25
5.3.210.0040.02712.34
5.3.200.0070.02412.35
5.3.190.0080.02912.23
5.3.180.0040.03212.47
5.3.170.0020.03012.42
5.3.160.0030.03212.50
5.3.150.0050.03012.44
5.3.140.0030.03112.42
5.3.130.0060.02812.37
5.3.120.0040.03112.43
5.3.110.0100.02212.38
5.3.100.0060.02912.25
5.3.90.0030.03012.26
5.3.80.0060.03012.06
5.3.70.0050.03012.20
5.3.60.0030.02912.11
5.3.50.0080.03012.13
5.3.40.0130.02712.09
5.3.30.0080.03111.98
5.3.20.0060.03011.87
5.3.10.0100.02511.77
5.3.00.0040.02911.83

preferences:
35.29 ms | 400 KiB | 5 Q