3v4l.org

run code in 300+ PHP versions simultaneously
#!/usr/bin/env php <?php $ts = date_timestamp_get(date_create()); $pdu6 = new PduStats(6, $ts); //$pdu6->toArray(); //$pdu6->putval(); $pdu7 = new PduStats(7, $ts); //$pdu7->toArray(); //$pdu7->putval(); class PduStats { /** * Statistics * @var array */ private $stats = array(); private $host; private $cookie; private $baseurl; private static $st; /** * Constructor. * * @param integer $id PDU identifier */ public function __construct($id, $TS, $user = 'apc', $pass = 'apc') { $this->ts = $TS; $this->cookie = tempnam(sys_get_temp_dir(), 'ucspdu-'); $this->host = "10.10.254.${id}"; $loginUrl = "http://".$this->host."/Forms/login1"; $datosLogin = 'login_username='.$user.'&login_password='.$pass; // Hacemos logging para obtener la cookie $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $loginUrl); curl_setopt($ch, CURLOPT_POST, 1); // a 0 curl_setopt($ch, CURLOPT_POSTFIELDS, $datosLogin); curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch); $url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL); if (!preg_match('@(http://[^/]+/[^/]+/[^/]+/)@Ui', $url, $match)) { throw new RuntimeException('No redirection'); } $this->baseurl=$match[0]; curl_close($ch); $this->toArray(); $this->putval(); $this->close(); } public function close() { // Logout $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->baseurl . 'logout.htm'); curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_exec($ch); curl_close($ch); // Delete cookie unlink($this->cookie); } public function toArray() { $this->getDeviceInfo(); $this->getPhaseInfo(); $this->getBankInfo(); } protected function getDeviceInfo() { // Parse info preg_match_all( '@<span name="Value_with_Units\?\d+,\d">([0-9.]+) \w+<@Ui', $this->getUrl('loadman.htm'), $matches, PREG_SET_ORDER ); // Store clean stats $this->stats['device']['load'] = 0 + $matches[0][1]; $this->stats['device']['peak'] = 0 + $matches[1][1]; $this->stats['device']['total'] = 0 + $matches[2][1]; } protected function getPhaseInfo() { // Parse info preg_match_all( '@<tr>\s*<td noWrap>&nbsp;([^<]+)</td>\s*<td noWrap>(\d+\.?\d*)\D*</td>\s*<td noWrap>(\d+\.?\d*)\D*</td>\s*<td noWr $this->getUrl('phload.htm'), $matches, PREG_SET_ORDER ); // Store clean stats foreach ($matches as $match) { $this->stats['phases'][substr($match[1],1,1)]['V'] = 0 + $match[2]; $this->stats['phases'][substr($match[1],1,1)]['kW'] = 0 + $match[3]; $this->stats['phases'][substr($match[1],1,1)]['A'] = 0 + $match[4]; } } protected function getBankInfo() { //Parse info preg_match_all( '@<tr>\s*<td noWrap>&nbsp;([^<]+)</td>\s*<td noWrap>(\d+\.?\d*)\D*</td>@Uis', $this->getUrl('bankload.htm'), $matches, PREG_SET_ORDER ); // list($dummy, $bankid, $amp) = $match; // Store clean stats foreach ($matches as $match) { $this->stats['banks'][$match[1]]['A'] = 0 + $match[2]; $phase = floor(($match[1] - 1) / 2) + 1; $this->stats['banks'][$match[1]]['V'] = $this->stats['phases'][$phase]['V']; $this->stats['banks'][$match[1]]['kW'] = $this->stats['banks'][$match[1]]['A'] * $this->stats['banks'][$match[1]]['V'] / 1000; } } private function getUrl($uri) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $this->baseurl . $uri); curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $content = curl_exec($ch); curl_close($ch); return $content; } public function putval() { var_dump(this->host); $list = array ( array('aaa', 'bbb', 'ccc', 'dddd'), array('123', '456', '789'), array('"aaa"', '"bbb"') ); $file = "/var/lib/rrdcached/db/UcsToCsv.csv"; $fp = fopen($file , "r+"); foreach ($list as $fields) { fputcsv($fp, $fields); } fclose($fp); } /* public function putval() { foreach ($this->stats as $key1 => $pdu){ switch ($key1){ case "device": echo "PUTVAL \"".$this->host."/DEVICE/pdu_global\" ".$this->ts.":${pdu['total']}:${pdu['load']}\n"; break; case "phases": foreach ($pdu as $key2 => $type){ echo "PUTVAL \"".$this->host."/PHASE-$key2/pdu_phase\" ".$this->ts.":${type['V']}:${type['kW']} } break; case "banks": foreach ($pdu as $key2 => $type){ $idPhase = floor(($key2+1)/2); $idBank = ($key2+1)%2+1; echo "PUTVAL \"".$this->host."/PHASE-${idPhase}/pdu_bank-${idBank}\" ".$this->ts.":${type['V']}:${type[ } break; } } }*/

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)
5.4.300.0270.06319.31
5.4.290.0530.05018.85
5.4.280.0370.04019.00
5.4.270.0400.05319.02
5.4.260.0330.04019.21
5.4.250.0400.06019.11
5.4.240.0400.06019.05
5.4.230.0270.04019.21
5.4.220.0330.07019.05
5.4.210.0200.04319.21
5.4.200.0430.06318.88
5.4.190.0270.04319.01
5.4.180.0370.05718.88
5.4.170.0230.04018.90
5.4.160.0230.03719.04
5.4.150.0230.08019.06
5.4.140.0330.06316.37
5.4.130.0270.03716.38
5.4.120.0270.07016.32
5.4.110.0200.04016.36
5.4.100.0300.05716.57
5.4.90.0300.07016.47
5.4.80.0270.07016.55
5.4.70.0270.04716.59
5.4.60.0230.07316.19
5.4.50.0270.05016.18
5.4.40.0330.03016.34
5.4.30.0300.05016.55
5.4.20.0270.04016.34
5.4.10.0230.05016.56
5.4.00.0270.04015.96
5.3.280.0330.07014.55
5.3.270.0330.03714.63
5.3.260.0300.06314.72
5.3.250.0370.06714.55
5.3.240.0300.06714.80
5.3.230.0400.06314.54
5.3.220.0400.03314.58
5.3.210.0230.04714.61
5.3.200.0330.05714.83
5.3.190.0370.03314.72
5.3.180.0370.06014.65
5.3.170.0370.06714.57
5.3.160.0370.03714.68
5.3.150.0330.03314.60
5.3.140.0330.03314.56
5.3.130.0330.06314.66
5.3.120.0270.04714.59
5.3.110.0400.06014.59
5.3.100.0370.03714.10
5.3.90.0300.03014.03
5.3.80.0230.03714.17
5.3.70.0300.03713.98
5.3.60.0370.05713.99
5.3.50.0330.02714.04
5.3.40.0270.07013.89
5.3.30.0270.04314.02
5.3.20.0200.05313.66
5.3.10.0370.05013.60
5.3.00.0230.03713.90

preferences:
140.68 ms | 1394 KiB | 7 Q