3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Solr_Importer_Ee { protected $_restClient = null; protected $_solr = null; public function __construct(Solr $solr) { $this->_solr = $solr; $this->_restClient = $solr->getRestClient(); } public function update() { $this->_bootstrap(); $items = $this->getItems('updated_date > '.$GLOBALS['_SOLR']['lastRunTime']); $client = $this->_restClient; $cores = $this->_solr->config('ee_cores'); $client->setCore($cores[0]); $model = new Solr_Model_Ee(); foreach ($items as $item) { $client->add($model->as_document($item)); } } public function reindex() { $this->_bootstrap(); $client = $this->_restClient; $cores = $this->_solr->config('ee_cores'); $liveCore = $cores[0]; $deckCore = $cores[1]; echo "using $deckCore...\n"; $this->_restClient->setCore($deckCore); $this->_restClient->deleteIndex(); echo "Starting data import into index...\n"; @set_time_limit(-1); // Expand upon ExpressionEngines timeouts, set to infinite. $items = $this->getItems(); $model = new Solr_Model_Ee(); foreach ($items as $item) { $client->add($model->as_document($item)); } $this->_restClient->swapCores($deckCore, $liveCore); } /** * Bootstraps EE * @throws Exception * @return */ protected function _bootstrap() { try { $system_path = realpath($this->_solr->getAppDir().$this->_solr->config('ee_app_path')); set_include_path(get_include_path() . PATH_SEPARATOR . $system_path); // Here, if we don't create that controller, it won't work // class Required_Controller extends CI_Controller {} $assign_to_config['enable_query_strings'] = TRUE; $assign_to_config['subclass_prefix'] = 'EE_'; if (realpath($system_path) !== FALSE) { $system_path = realpath($system_path).'/'; } // ensure there's a trailing slash $system_path = rtrim($system_path, '/').'/'; $_SERVER['REQUEST_URI'] = 'solr.gif'; define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME)); define('EXT', '.php'); define('BASEPATH', str_replace("\\", "/", $system_path.'codeigniter/system/')); define('APPPATH', $system_path.'expressionengine/'); define('FCPATH', str_replace(SELF, '', __FILE__)); define('SYSDIR', trim(strrchr(trim(str_replace("\\", "/", $system_path), '/'), '/'), '/')); define('UTF8_ENABLED', false); define('CI_VERSION', '2.0'); //define('AJAX_REQUEST',false); define('DEBUG',false); require BASEPATH.'core/Common'.EXT; require APPPATH.'config/constants'.EXT; $CFG =& load_class('Config', 'core'); $URI =& load_class('URI', 'core'); $IN =& load_class('Input', 'core'); $OUT =& load_class('Output', 'core'); $LANG =& load_class('Lang', 'core'); $SEC =& load_class('Security', 'core'); $loader = load_class('Loader', 'core'); // Load the base controller class require BASEPATH.'core/Controller'.EXT; function &get_instance() { return CI_Controller::get_instance(); } $EE = @new Solr_Importer_Ee_Bootstrap; $this->EE = $EE; return $this->EE; } catch (Exception $e) { throw new Exception($e->getMessage()); } } public function getItems($filter = null) { $channelList = $this->_solr->config('channels'); $SOLR_entries = array(); $site_mapping = $this->_solr->config('ee_sites'); $configSites = $this->_solr->config('ee_sites'); if ( ! is_array( $configSites ) ) { die('Site and Store IDs need to be defined in config.php'); } // retrieve all channels we have defined in the config. $this->EE->db->where_in('channel_name', array_keys($channelList)); $channels = $this->EE->db->get('channels' )->result(); foreach($channels as $channel) { // Retrieve all custom fields $fields = $this->EE->db->get_where('channel_fields', array( 'group_id' => $channel->field_group ) )->result(); //Grab all the categories for an entry $this->EE->db->select('(select GROUP_CONCAT(cat_name) from exp_category_posts cp join exp_categories c on c.cat_id = cp.cat_id where cp.entry_id = exp_d.entry_id) as cats', false); // Build out which custom fields we need and get entries $channel_title_fields = array('entry_id','title','url_title','status','year','month','day','entry_date'); foreach( $channel_title_fields as $i) $this->EE->db->select('t.' . $i); $this->EE->db->select('unix_timestamp(t.edit_date) as updated_date'); $this->EE->db->join('channel_titles t', 't.entry_id=d.entry_id'); $this->EE->db->join('channel_data pd', 'pd.entry_id=d.entry_id'); //$this->EE->db->select('pl.short_name')->join('publisher_languages pl', 'pl.id=pd.publisher_lang_id'); $field_map = array(); foreach($fields as $field) { $this->EE->db->select("pd.field_id_{$field->field_id}"); $field_map[ 'field_' . $field->field_name] = 'field_id_' . $field->field_id; } $this->EE->db->where('d.channel_id', $channel->channel_id); if ($filter) { $filter = str_replace('updated_date', 'unix_timestamp(t.edit_date)', $filter); $this->EE->db->where($filter); } $this->EE->db->where('t.status', 'open'); $entries = $this->EE->db->get('channel_data exp_d'); // Build items. foreach( $entries->result() as $entry ) { $base_item = $this->makeItem( $channel, $field_map, $entry ); /** * Figure out solr id for content */ $base_item['site_id'] = 1;//hard coding until multi site is needed - $site_mapping[$entry->short_name]; $SOLR_entries[] = $base_item; } } return $SOLR_entries; } function makeItem( $channel, $fieldmap, $entry ) { $data = array(); $tmpdata = array(); $data['entry_id'] = $entry->entry_id; $data['channel_id'] = $channel->channel_id; $data['channel_name'] = $channel->channel_name; $data['channel_title'] = htmlentities($channel->channel_title); $data['title'] = $entry->title; $data['status'] = $entry->status; $data['updated'] = $entry->entry_date; $data['category'] = explode(',',$entry->cats); //$data['fields'] = Solr::config('defaults'); $channelRules = $this->_solr->config('channels'); if ( array_key_exists( $channel->channel_name, $channelRules ) ) { // if this channel has custom fields $fields = $channelRules[$channel->channel_name]; foreach($fields as $field => $rules) { is_array($rules) or $rules = array( 'type' => '', 'value' => $rules); preg_match_all('/@\!(\w+)/', $rules['value'], $matches); // handle tmp fields foreach($matches[1] as $match) { $tmp = array_key_exists($match, $tmpdata) ? $tmpdata[$match] : ''; $rules['value'] = str_replace('@!' . $match, $tmp, $rules['value']); } unset($matches); preg_match_all('/@(\w+)/', $rules['value'], $matches); foreach($matches[1] as $orig_match) { $match = array_key_exists($orig_match, $fieldmap) ? $fieldmap[$orig_match] : $orig_match; $tmp = property_exists($entry, $match) ? $entry->{$match} : (property_exists($channel, $match) ? $channel->{$match}: $match); $rules['value'] = str_replace('@' . $orig_match, $tmp, $rules['value']); } unset($matches); switch ($rules['type']) { case 'expression': $rules['value'] = $this->parse( $rules['value'] ); break; default: $rules['value'] = filter_var( strip_tags($rules['value']), FILTER_SANITIZE_STRING); //$rules['value'] = filter_var($rules['value'], FILTER_SANITIZE_STRING); } switch (@$rules['save']) { case 'tmp': $tmpdata[$field] = $rules['value']; break; default: $data['fields'][$field] = $rules['value']; } } } return $data; } }

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.0100.01017.95
8.3.50.0070.01321.95
8.3.40.0090.01218.79
8.3.30.0120.00319.27
8.3.20.0090.00920.47
8.3.10.0080.00023.70
8.3.00.0000.00820.95
8.2.180.0150.00318.29
8.2.170.0090.00622.96
8.2.160.0090.00620.65
8.2.150.0050.00324.18
8.2.140.0000.00824.66
8.2.130.0000.00826.16
8.2.120.0040.00418.86
8.2.110.0030.00622.31
8.2.100.0070.00320.71
8.2.90.0040.00419.14
8.2.80.0060.00317.97
8.2.70.0040.00717.50
8.2.60.0110.00417.93
8.2.50.0000.00918.07
8.2.40.0000.00819.76
8.2.30.0070.00018.36
8.2.20.0060.00317.70
8.2.10.0000.00818.13
8.2.00.0090.00317.62
8.1.280.0060.00825.92
8.1.270.0080.00023.92
8.1.260.0000.00826.35
8.1.250.0100.00028.09
8.1.240.0030.00623.89
8.1.230.0000.01119.20
8.1.220.0000.00917.79
8.1.210.0040.00418.77
8.1.200.0040.00417.23
8.1.190.0030.00517.25
8.1.180.0000.00918.10
8.1.170.0090.00018.57
8.1.160.0040.00421.98
8.1.150.0000.00918.70
8.1.140.0040.00417.48
8.1.130.0000.00717.98
8.1.120.0040.00417.40
8.1.110.0080.00017.43
8.1.100.0000.00717.40
8.1.90.0000.00717.44
8.1.80.0000.00817.38
8.1.70.0040.00417.44
8.1.60.0110.00617.50
8.1.50.0060.00317.57
8.1.40.0060.00317.53
8.1.30.0040.00417.50
8.1.20.0030.00517.52
8.1.10.0030.00517.54
8.1.00.0050.00317.46
8.0.300.0050.00318.77
8.0.290.0000.00816.75
8.0.280.0070.00018.48
8.0.270.0000.00717.20
8.0.260.0030.00317.22
8.0.250.0050.00217.01
8.0.240.0000.01017.00
8.0.230.0070.00017.02
8.0.220.0040.00416.95
8.0.210.0030.00316.91
8.0.200.0000.00716.98
8.0.190.0070.00016.88
8.0.180.0080.00016.87
8.0.170.0000.00916.94
8.0.160.0040.00416.86
8.0.150.0040.00416.79
8.0.140.0110.00016.85
8.0.130.0000.00613.30
8.0.120.0040.00416.79
8.0.110.0000.00816.91
8.0.100.0030.00616.91
8.0.90.0040.00416.86
8.0.80.0060.00916.90
8.0.70.0000.00816.90
8.0.60.0040.00416.95
8.0.50.0040.00416.85
8.0.30.0120.01217.18
8.0.20.0170.00517.41
8.0.10.0050.00316.92
8.0.00.0100.01016.91
7.4.330.0050.00015.00
7.4.320.0030.00316.52
7.4.300.0060.00016.53
7.4.290.0060.00316.60
7.4.280.0040.00416.51
7.4.270.0070.00016.45
7.4.260.0030.00516.53
7.4.250.0090.00016.61
7.4.240.0020.00616.57
7.4.230.0000.00716.72
7.4.220.0070.01116.59
7.4.210.0000.01816.70
7.4.200.0000.00716.72
7.4.160.0070.01016.52
7.4.150.0120.00617.40
7.4.140.0090.00917.86
7.4.130.0050.01416.51
7.4.120.0100.01016.52
7.4.110.0070.01016.56
7.4.100.0100.01016.47
7.4.90.0120.00616.41
7.4.80.0080.01219.39
7.4.70.0100.00716.53
7.4.60.0190.00316.45
7.4.50.0000.00516.46
7.4.40.0120.00916.44
7.4.30.0070.01016.60
7.4.10.0030.01615.02
7.4.00.0070.01015.02
7.3.330.0030.00313.32
7.3.320.0050.00013.13
7.3.310.0040.00416.35
7.3.300.0070.00016.37
7.3.290.0090.00616.35
7.3.280.0090.01116.31
7.3.270.0100.00717.40
7.3.260.0120.01016.55
7.3.250.0130.00816.40
7.3.240.0090.00916.32
7.3.230.0150.00016.39
7.3.210.0040.01316.36
7.3.200.0090.01319.39
7.3.190.0200.00416.56
7.3.180.0110.00416.49
7.3.170.0070.01016.59
7.3.160.0110.01116.62
7.3.130.0100.01014.77
7.3.120.0100.00714.82
7.3.110.0030.00914.83
7.3.100.0030.00714.35
7.3.90.0060.00914.76
7.3.80.0100.00314.80
7.3.70.0060.00914.56
7.3.60.0000.01114.93
7.3.50.0100.00314.74
7.3.40.0030.01014.83
7.3.30.0040.01114.56
7.3.20.0030.00616.52
7.3.10.0060.01216.38
7.3.00.0080.00816.66
7.2.330.0070.01816.59
7.2.320.0150.00316.63
7.2.310.0100.01016.49
7.2.300.0100.00616.77
7.2.290.0030.01516.80
7.2.260.0060.01215.03
7.2.250.0100.01015.13
7.2.240.0070.00714.85
7.2.230.0090.00614.88
7.2.220.0060.00914.90
7.2.210.0090.00614.67
7.2.200.0030.01014.94
7.2.190.0070.00314.92
7.2.180.0040.01115.04
7.2.170.0030.00614.65
7.2.160.0000.01515.02
7.2.150.0070.00716.66
7.2.140.0070.00716.52
7.2.130.0030.01316.67
7.2.120.0100.00316.62
7.2.110.0030.00716.47
7.2.100.0060.00616.37
7.2.90.0040.01116.82
7.2.80.0000.01816.52
7.2.70.0030.00616.56
7.2.60.0030.01016.75
7.2.50.0060.01016.83
7.2.40.0070.01116.73
7.2.30.0050.00816.38
7.2.20.0060.00916.68
7.2.10.0060.00616.53
7.2.00.0000.01416.54
7.1.330.0060.00915.67
7.1.320.0040.00715.51
7.1.310.0120.00315.60
7.1.300.0040.00415.39
7.1.290.0090.00615.65
7.1.280.0090.00315.64
7.1.270.0030.00815.49
7.1.260.0070.00715.41
7.1.250.0060.00615.72
7.1.240.0070.00715.59
7.1.230.0030.00615.74
7.1.220.0070.00715.71
7.1.210.0100.00315.53
7.1.200.0030.00715.58
7.1.190.0030.00915.21
7.1.180.0030.01315.61
7.1.170.0070.01015.44
7.1.160.0060.00915.57
7.1.150.0030.00915.70
7.1.140.0070.00715.65
7.1.130.0080.00415.57
7.1.120.0150.00415.44
7.1.110.0110.00415.68
7.1.100.0100.00015.56
7.1.90.0030.01015.57
7.1.80.0040.01115.67
7.1.70.0040.00616.39
7.1.60.0080.01017.52
7.1.50.0070.01216.09
7.1.40.0030.00915.75
7.1.30.0000.01115.78
7.1.20.0060.00915.73
7.1.10.0000.01515.71
7.1.00.0020.04618.84
7.0.330.0070.01015.42
7.0.320.0030.00815.04
7.0.310.0060.00314.93
7.0.300.0030.01415.21
7.0.290.0060.00915.11
7.0.280.0120.00315.43
7.0.270.0070.00315.04
7.0.260.0040.01115.03
7.0.250.0070.01015.08
7.0.240.0000.00815.04
7.0.230.0070.00415.22
7.0.220.0000.01315.20
7.0.210.0070.00715.47
7.0.200.0050.00615.98
7.0.190.0040.00415.11
7.0.180.0000.01415.13
7.0.170.0030.01015.42
7.0.160.0000.01315.32
7.0.150.0030.01015.22
7.0.140.0030.04318.59
7.0.130.0160.00015.16
7.0.120.0070.00315.28
7.0.110.0070.02417.69
7.0.100.0050.04817.70
7.0.90.0130.04517.61
7.0.80.0080.04217.56
7.0.70.0060.04617.55
7.0.60.0130.03517.55
7.0.50.0050.04217.80
7.0.40.0050.04616.65
7.0.30.0040.03516.63
7.0.20.0030.02316.48
7.0.10.0100.02716.55
7.0.00.0070.03516.57
5.6.400.0100.00714.09
5.6.390.0090.00914.35
5.6.380.0090.00014.45
5.6.370.0000.01314.37
5.6.360.0040.01514.14
5.6.350.0000.01314.26
5.6.340.0030.01014.33
5.6.330.0060.00614.02
5.6.320.0100.00714.29
5.6.310.0060.00914.32
5.6.300.0120.00614.01
5.6.290.0030.01014.21
5.6.280.0140.03517.67
5.6.270.0040.01114.09
5.6.260.0090.02117.56
5.6.250.0080.04017.58
5.6.240.0030.05017.42
5.6.230.0080.04217.31
5.6.220.0120.03817.52
5.6.210.0050.05017.38
5.6.200.0120.04217.52
5.6.190.0050.03217.45
5.6.180.0050.03217.46
5.6.170.0080.04017.47
5.6.160.0060.04817.55
5.6.150.0060.04617.57
5.6.140.0050.04817.53
5.6.130.0050.04717.54
5.6.120.0050.02017.48
5.6.110.0060.03917.40
5.6.100.0080.04317.48
5.6.90.0040.03917.45
5.6.80.0050.04117.14
5.6.70.0070.04516.97
5.6.60.0020.05017.08
5.6.50.0050.04917.12
5.6.40.0050.02517.06
5.6.30.0130.01817.06
5.6.20.0030.05317.07
5.6.10.0060.03817.12
5.6.00.0050.03717.20
5.5.380.0060.04315.98
5.5.370.0080.03815.79
5.5.360.0050.03515.86
5.5.350.0090.04015.66
5.5.340.0070.04316.18
5.5.330.0060.04015.91
5.5.320.0100.03716.11
5.5.310.0120.03416.11
5.5.300.0050.04416.01
5.5.290.0050.04516.15
5.5.280.0080.04316.25
5.5.270.0030.04316.11
5.5.260.0040.04716.06
5.5.250.0030.04716.11
5.5.240.0030.03715.71
5.5.230.0090.04015.79
5.5.220.0050.04715.78
5.5.210.0070.04515.72
5.5.200.0040.03115.71
5.5.190.0120.04015.86
5.5.180.0100.02715.70
5.5.170.0110.00313.81
5.5.160.0080.03515.85
5.5.150.0100.04215.75
5.5.140.0090.03515.73
5.5.130.0060.04315.83
5.5.120.0070.04415.51
5.5.110.0070.04115.57
5.5.100.0080.03715.73
5.5.90.0090.03315.56
5.5.80.0090.03815.53
5.5.70.0030.02815.61
5.5.60.0060.04015.67
5.5.50.0050.03915.64
5.5.40.0030.02715.68
5.5.30.0030.03915.67
5.5.20.0030.04715.58
5.5.10.0050.04215.49
5.5.00.0130.02815.68
5.4.450.0050.04115.19
5.4.440.0050.04215.28
5.4.430.0060.04515.07
5.4.420.0020.04715.32
5.4.410.0050.03915.25
5.4.400.0050.03914.94
5.4.390.0020.02714.89
5.4.380.0030.02514.98
5.4.370.0060.03914.99
5.4.360.0070.03314.86
5.4.350.0100.03714.87
5.4.340.0080.03614.98
5.4.330.0050.00510.84
5.4.320.0030.02514.98
5.4.310.0050.04215.03
5.4.300.0080.03914.88
5.4.290.0080.02214.93
5.4.280.0080.04114.86
5.4.270.0040.03514.99
5.4.260.0050.04214.87
5.4.250.0070.04015.00
5.4.240.0070.03714.99
5.4.230.0050.04215.00
5.4.220.0100.03214.83
5.4.210.0050.04214.93
5.4.200.0100.03514.85
5.4.190.0070.04014.80
5.4.180.0050.03114.87
5.4.170.0030.02814.80
5.4.160.0050.03314.89
5.4.150.0070.04515.05
5.4.140.0030.04113.52
5.4.130.0100.03313.52
5.4.120.0030.02213.70
5.4.110.0020.02213.59
5.4.100.0020.02713.69
5.4.90.0030.03613.76
5.4.80.0090.03313.66
5.4.70.0050.02113.71
5.4.60.0050.04313.69
5.4.50.0080.04013.59
5.4.40.0060.04313.68
5.4.30.0040.03913.60
5.4.20.0050.02213.73
5.4.10.0030.03113.54
5.4.00.0000.02713.28
5.3.290.0130.07714.85
5.3.280.0030.06714.71
5.3.270.0100.07314.70
5.3.260.0130.05714.73
5.3.250.0070.07314.78
5.3.240.0130.06714.68
5.3.230.0170.06314.92
5.3.220.0100.07014.53
5.3.210.0030.07714.75
5.3.200.0030.07714.66
5.3.190.0030.07714.67
5.3.180.0070.07314.66
5.3.170.0070.05314.76
5.3.160.0100.07314.66
5.3.150.0100.04014.66
5.3.140.0100.07014.79
5.3.130.0200.06014.60
5.3.120.0070.07014.65
5.3.110.0070.07014.77
5.3.100.0070.04314.14
5.3.90.0100.06714.09
5.3.80.0100.05714.06
5.3.70.0100.07314.25
5.3.60.0130.03714.22
5.3.50.0030.07014.04
5.3.40.0130.06714.00
5.3.30.0070.06014.07
5.3.20.0100.05013.87
5.3.10.0070.06713.70
5.3.00.0000.04713.86

preferences:
45.97 ms | 401 KiB | 5 Q