3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @package Joomla.Cli * * @copyright (C) 2012 Open Source Matters, Inc. <https://www.joomla.org> * @license GNU General Public License version 2 or later; see LICENSE.txt */ /** * A command line cron job to bulk import JSON data into Joomla articles */ // Initialize Joomla framework const _JEXEC = 1; // Load system defines if (file_exists(__DIR__ . '/defines.php')) { require_once __DIR__ . '/defines.php'; } if (!defined('_JDEFINES')) { define('JPATH_BASE', __DIR__); require_once JPATH_BASE . '/includes/defines.php'; } // Get the framework. require_once JPATH_LIBRARIES . '/import.legacy.php'; // Bootstrap the CMS libraries. require_once JPATH_LIBRARIES . '/cms.php'; class BulkArticles extends JApplicationCli { public function doExecute(): void { $this->out(JText::_('Start')); // Fetch the JSON data and Run the insertArticle bulk data import to articles function $curlOpts = [ CURLOPT_URL => 'https://api.dtn.com/publishing/news/articles?categoryId=16%2C17%2C18&limit=10&maxAge=30&apikey=placeholder', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'GET', ]; try { $fetchedArticles = $this->curlToObject($curlOpts); if ($fetchedArticles) { $this->out(JText::_('Fetched Articles: ' . count($fetchedArticles))); } $insertedIds = $this->insertArticles($fetchedArticles); if ($insertedIds) { $this->out(JText::_('Inserted IDs: ' . implode(', ', $insertedIds))); } } catch (exception $e) { $this->out(JText::_($e->getMessage())); } $this->out(JText::_('Complete')); } /** * @throws Exception */ private function curlToObject(array $curlOpts): array { $ch = curl_init(); curl_setopt_array($ch, $curlOpts); $result = curl_exec($ch); $error = curl_error($ch); // Get the last error curl_close($ch); if ($error) { throw new Exception($error); } return json_decode($result); } /** * @throws Exception */ private function insertArticles(array $articles): array { require_once JPATH_ADMINISTRATOR . '/components/com_content/models/article.php'; $articleModel = new ContentModelArticle([]); foreach ($articles as $article) { $articleData = [ 'id' => 0, 'catid' => 8, 'title' => ucwords(strtolower($article->title)), 'alias' => JFilterOutput::stringURLSafe($article->title), 'introtext' => strip_tags($article->storySummary), 'fulltext' => strip_tags($article->content), 'state' => 1, 'access' => 2, 'created_by' => 332, 'language' => '*', 'rules' => [ 'core.edit.delete' => [], 'core.edit.edit' => [], 'core.edit.state' => [] ], ]; if (!$articleModel->save($articleData)) { throw new Exception($articleModel->getError()); } else { $newIds[] = $articleModel->getItem()->id; } } return $newIds ?? []; } } JApplicationCli::getInstance('BulkArticles')->execute();

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.70.0040.01216.88
8.3.60.0090.01216.88
8.3.50.0110.01120.24
8.3.40.0040.01418.73
8.3.30.0140.00318.88
8.3.20.0030.00624.18
8.3.10.0110.00724.66
8.3.00.0040.00426.16
8.2.190.0100.01016.63
8.2.180.0070.01425.92
8.2.170.0130.00719.21
8.2.160.0080.00622.96
8.2.150.0000.00825.66
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0060.00318.89
8.2.110.0060.00322.25
8.2.100.0030.01019.52
8.2.90.0030.00517.88
8.2.80.0000.00818.86
8.2.70.0030.00617.63
8.2.60.0080.00018.04
8.2.50.0060.00318.07
8.2.40.0000.00818.35
8.2.30.0040.00418.20
8.2.20.0040.00420.64
8.2.10.0040.00417.70
8.2.00.0040.00419.37
8.1.280.0040.01125.92
8.1.270.0050.00324.02
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0090.00019.09
8.1.230.0060.00617.95
8.1.220.0000.00817.78
8.1.210.0060.00318.77
8.1.200.0040.00417.25
8.1.190.0000.00917.35
8.1.180.0060.00318.10
8.1.170.0050.00318.71
8.1.160.0040.00418.90
8.1.150.0000.00818.53
8.1.140.0080.00017.34
8.1.130.0060.00319.18
8.1.120.0100.00017.37
8.1.110.0000.00817.36
8.1.100.0080.00017.36
8.1.90.0040.00417.36
8.1.80.0000.00817.41
8.1.70.0050.00317.48
8.1.60.0040.00417.54
8.1.50.0000.00817.58
8.1.40.0050.00317.63
8.1.30.0090.00017.62
8.1.20.0180.00717.69
8.1.10.0130.01317.59
8.1.00.0130.01317.49
8.0.300.0080.00018.77
8.0.290.0050.00317.00
8.0.280.0040.00418.46
8.0.270.0040.00317.03
8.0.260.0030.00316.97
8.0.250.0060.00317.14
8.0.240.0000.00717.09
8.0.230.0030.00317.14
8.0.220.0000.00717.09
8.0.210.0080.00017.13
8.0.200.0070.00017.04
8.0.190.0040.00417.13
8.0.180.0080.00017.03
8.0.170.0040.00417.11
8.0.160.0080.00417.05
8.0.150.0170.00417.01
8.0.140.0170.00316.86
8.0.130.0140.00716.83
8.0.120.0220.00016.95
8.0.110.0140.00716.92
8.0.100.0130.00717.00
8.0.90.0160.00417.08
8.0.80.0180.00317.07
8.0.70.0100.01017.05
8.0.60.0190.00317.02
8.0.50.0200.00016.96
8.0.30.0120.00816.93
8.0.20.0100.01017.09
8.0.10.0140.00917.02
7.4.330.0020.00215.55
7.4.320.0060.00316.66
7.4.300.0080.00016.50
7.4.290.0050.00216.68
7.4.280.0090.00016.58
7.4.270.0180.00516.46
7.4.260.0070.00716.57
7.4.250.0130.00816.56
7.4.240.0180.00416.55
7.4.230.0170.00016.65
7.4.220.0100.00716.53
7.4.210.0120.00816.66
7.4.200.0160.00316.66
7.4.190.0170.00616.64
7.4.180.0190.00016.64
7.4.160.0130.00616.74
7.4.150.0130.00716.56
7.4.140.0130.00516.62
7.4.130.0160.00316.42
7.4.120.0130.00816.47
7.4.110.0180.00416.59
7.4.100.0180.00316.60
7.4.90.0130.00716.35
7.4.80.0090.00916.59
7.4.70.0090.00516.55
7.4.60.0110.00216.51
7.4.50.0150.00016.25
7.4.40.0180.00016.52
7.4.30.0140.00716.43
7.4.20.0150.00516.43
7.4.10.0070.00716.37
7.4.00.0190.00016.49

preferences:
47.32 ms | 401 KiB | 5 Q