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 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; } } } /** * Returns the Contact people of a given Address ID. * * @param int $address_id Address ID * @return array */ public function getContacts( $address_id ) { if ( ( $this->check_cache == 2 ) && Cache::has( 'collivery.contacts.'. $this->client_id .'.'. $address_id ) ) { return Cache::get( 'collivery.contacts.'. $this->client_id .'.'. $address_id ); } else { try { $result = $this->client()->get_contacts( $address_id, $this->token ); } catch (SoapFault $e) { $this->catchSoapFault( $e ); return false; } if ( isset( $result['contacts'] ) ) { if ( $this->check_cache != 0 ) Cache::put( 'collivery.contacts.'. $this->client_id .'.'. $address_id, $result['contacts'], 60*24 ); return $result['contacts']; } 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 POD image for a given Waybill Number. * * @param int $collivery_id Collivery waybill number * @return array */ public function getPod( $collivery_id ) { if ( ( $this->check_cache == 2 ) && Cache::has( 'collivery.pod.'. $this->client_id .'.'. $collivery_id ) ) { return Cache::get( 'collivery.pod.'. $this->client_id .'.'. $collivery_id ); } else { try { $result = $this->client()->get_pod( $collivery_id, $this->token ); } catch (SoapFault $e) { $this->catchSoapFault( $e ); return false; } if ( isset( $result['pod'] ) ) { if ( isset( $result['error_id'] ) ) $this->setError( $result['error_id'], $result['error'] ); else if ( $this->check_cache != 0 ) Cache::put( 'collivery.pod.'. $this->client_id .'.'. $collivery_id, $result['pod'], 60*24 ); return $result['pod']; } 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 avaibale parcel images for a given Waybill Number. * * @param int $collivery_id Collivery waybill number * @return array */ public function getParcelImageList( $collivery_id ) { if ( ( $this->check_cache == 2 ) && Cache::has( 'collivery.parcel_image_list.'. $this->client_id .'.'. $collivery_id ) ) { return Cache::get( 'collivery.parcel_image_list.'. $this->client_id .'.'. $collivery_id ); } else { try { $result = $this->client()->get_parcel_image_list( $collivery_id, $this->token ); } catch (SoapFault $e) { $this->catchSoapFault( $e ); return false; } if ( isset( $result['images'] ) ) { if ( isset( $result['error_id'] ) ) $this->setError( $result['error_id'], $result['error'] ); else if ( $this->check_cache != 0 ) Cache::put( 'collivery.parcel_image_list.'. $this->client_id .'.'. $collivery_id, $result['images'], 60*12 ); return $result['images']; } 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 image of a given parcel-id of a waybill. * If the Waybill number is 54321 and there are 3 parcels, they would * be referenced by id's 54321-1, 54321-2 and 54321-3. * * @param string $parcel_id Parcel ID * @return array Array containing all the information * about the image including the image * itself in base64 */ public function getParcelImage( $parcel_id ) { if ( ( $this->check_cache == 2 ) && Cache::has( 'collivery.parcel_image.'. $this->client_id .'.'. $parcel_id ) ) { return Cache::get( 'collivery.parcel_image.'. $this->client_id .'.'. $parcel_id ); } else { try { $result = $this->client()->get_parcel_image( $parcel_id, $this->token ); } catch (SoapFault $e) { $this->catchSoapFault( $e ); return false; } if ( isset( $result['image'] ) ) { if ( isset( $result['error_id'] ) ) $this->setError( $result['error_id'], $result['error'] ); else if ( $this->check_cache != 0 ) Cache::put( 'collivery.parcel_image.'. $this->client_id .'.'. $parcel_id, $result['image'], 60*24 ); return $result['image']; } 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 status tracking detail of a given Waybill number. * If the collivery is still active, the estimated time of delivery * will be provided. If delivered, the time and receivers name (if availble) * with returned. * * @param int $collivery_id Collivery ID * @return array Collivery Status Information */ public function getStatus( $collivery_id ) { if ( ( $this->check_cache == 2 ) && Cache::has( 'collivery.status.'. $this->client_id .'.'. $collivery_id ) ) { return Cache::get( 'collivery.status.'. $this->client_id .'.'. $collivery_id ); } else { try { $result = $this->client()->get_collivery_status( $collivery_id, $this->token ); } catch (SoapFault $e) { $this->catchSoapFault( $e ); return false; } if ( isset( $result['status_id'] ) ) { if ( isset( $result['error_id'] ) ) $this->setError( $result['error_id'], $result['error'] ); else if ( $this->check_cache != 0 ) Cache::put( 'collivery.status.'. $this->client_id .'.'. $collivery_id, $result, 60*12 ); 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; } } } /** * 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; } }

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.2.00.0030.00919.35
7.1.100.0000.01417.95
7.1.70.0060.00317.01
7.1.60.0120.01219.43
7.1.50.0200.02034.36
7.1.00.0130.07022.40
7.0.200.0110.00416.61
7.0.140.0130.06322.01
7.0.100.0170.07020.02
7.0.90.0300.05020.00
7.0.80.0100.07320.11
7.0.70.0070.06720.02
7.0.60.0100.08019.94
7.0.50.0270.05020.30
7.0.40.0130.07019.96
7.0.30.0000.07020.15
7.0.20.0030.09020.07
7.0.10.0000.06720.04
7.0.00.0130.05020.09
5.6.280.0030.07020.95
5.6.250.0030.07720.86
5.6.240.0130.05320.77
5.6.230.0100.07720.71
5.6.220.0070.08020.71
5.6.210.0030.09320.50
5.6.200.0170.08321.13
5.6.190.0070.05321.10
5.6.180.0070.08321.03
5.6.170.0130.08021.05
5.6.160.0070.06321.15
5.6.150.0070.04021.14
5.6.140.0130.07721.02
5.6.130.0130.08021.25
5.6.120.0100.05321.22
5.6.110.0030.08721.03
5.6.100.0030.08021.15
5.6.90.0000.04721.23
5.6.80.0070.07720.55
5.6.70.0130.07020.54
5.6.60.0100.06720.55
5.6.50.0100.05720.40
5.6.40.0030.08720.55
5.6.30.0130.07320.41
5.6.20.0030.08020.48
5.6.10.0070.08020.49
5.6.00.0070.06720.47
5.5.380.0070.08320.50
5.5.370.0170.07720.63
5.5.360.0070.08320.58
5.5.350.0070.08720.50
5.5.340.0070.05720.87
5.5.330.0170.04720.73
5.5.320.0100.04320.93
5.5.310.0100.08020.85
5.5.300.0030.05321.00
5.5.290.0070.08720.84
5.5.280.0030.05320.82
5.5.270.0030.04720.72
5.5.260.0070.09721.01
5.5.250.0100.07720.77
5.5.240.0070.06720.11
5.5.230.0230.06720.35
5.5.220.0100.07020.20
5.5.210.0130.07020.29
5.5.200.0100.07020.33
5.5.190.0070.07320.24
5.5.180.0130.07720.18
5.5.160.0100.03320.29
5.5.150.0100.05320.30
5.5.140.0100.07720.27
5.5.130.0030.04720.34
5.5.120.0130.06320.36
5.5.110.0170.06020.18
5.5.100.0100.05720.07
5.5.90.0100.07720.20
5.5.80.0130.07320.25
5.5.70.0130.06320.18
5.5.60.0130.06720.05
5.5.50.0130.07320.12
5.5.40.0030.03720.14
5.5.30.0030.08020.23
5.5.20.0030.03720.17
5.5.10.0070.08020.13
5.5.00.0070.07020.14
5.4.450.0030.04319.22
5.4.440.0200.07319.36
5.4.430.0030.08719.23
5.4.420.0000.08319.39
5.4.410.0070.08019.27
5.4.400.0070.04719.24
5.4.390.0030.05019.09
5.4.380.0170.06719.07
5.4.370.0000.08318.93
5.4.360.0070.06319.23
5.4.350.0130.07718.88
5.4.340.0030.04719.08
5.4.320.0070.08018.93
5.4.310.0100.07319.14
5.4.300.0070.07318.97
5.4.290.0070.06719.04
5.4.280.0130.07719.13
5.4.270.0030.07719.23
5.4.260.0170.05718.91
5.4.250.0100.06318.87
5.4.240.0100.07019.04
5.4.230.0000.05019.22
5.4.220.0030.04018.90
5.4.210.0070.04319.20
5.4.200.0000.04019.05
5.4.190.0170.07019.06
5.4.180.0130.04319.24
5.4.170.0100.06318.96
5.4.160.0030.07019.14
5.4.150.0000.04718.86
5.4.140.0100.07016.51
5.4.130.0070.07316.39
5.4.120.0130.06316.42
5.4.110.0170.06016.50
5.4.100.0070.06016.43
5.4.90.0170.06016.57
5.4.80.0000.08016.54
5.4.70.0100.07016.37
5.4.60.0070.06316.54
5.4.50.0070.06316.50
5.4.40.0030.04716.57
5.4.30.0070.07016.49
5.4.20.0070.07316.42
5.4.10.0130.05316.50
5.4.00.0130.03015.93
5.3.290.0070.06014.93
5.3.280.0030.04014.86
5.3.270.0030.05714.79
5.3.260.0030.08314.79
5.3.250.0030.07314.80
5.3.240.0000.04714.85
5.3.230.0170.07014.65
5.3.220.0030.06714.67
5.3.210.0030.08314.68
5.3.200.0070.04714.84
5.3.190.0070.07014.64
5.3.180.0130.05714.70
5.3.170.0030.08314.75
5.3.160.0100.07014.61
5.3.150.0070.06014.80
5.3.140.0030.07714.65
5.3.130.0070.04314.78
5.3.120.0070.07714.79
5.3.110.0100.04314.77
5.3.100.0030.04014.22
5.3.90.0000.04014.21
5.3.80.0030.07714.27
5.3.70.0070.04014.13
5.3.60.0070.04314.12
5.3.50.0200.05714.14
5.3.40.0070.07314.16
5.3.30.0070.07313.93
5.3.20.0070.07013.83
5.3.10.0030.07013.88
5.3.00.0100.06313.80

preferences:
34.1 ms | 401 KiB | 5 Q