3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Install this pear extention on linux by doing: $ pear channel-discover phpquery-pear.appspot.com $ pear install phpquery/phpQuery */ require('phpQuery.php'); /** * Gets the server that a player has joined * @param string $username The username of the player * @return array An array that consists of: success, title, url and errorCode */ $username = "SoL0vex" ; function getJoinedServer ($username) { $curl = curl_init("http://battlelog.battlefield.com/bf3/user/$username"); curl_setopt($curl, CURLOPT_FAILONERROR, true); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_ENCODING, 'gzip'); curl_setopt($curl, CURLOPT_TIMEOUT, 30); $doc = phpQuery::newDocument(curl_exec($curl)); phpQuery::selectDocument($doc); $li = pq('.common-playing-link a'); if (pq($li)->attr('href')) { return array('success' => true, 'title' => pq($li)->attr('title'), 'url' => 'http://battlelog.battlefield.com' . pq($li)->attr('href')); } else { return array('success' => false, 'errorCode' => 1); } curl_close($curl); } // Measure time $mtime = microtime(); $mtime = explode(' ',$mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; // Get joined server $result = getJoinedServer((isset($_GET['user']) ? $_GET['user'] : 'diegorod')); if($result['success']) { echo "<a href='${result['url']}'>${result['title']}</a>"; } elseif ($result['errorCode'] === 1) { echo 'User not playing'; } // Stop measuring time $mtime = microtime(); $mtime = explode(' ',$mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $totaltime = ($endtime - $starttime); // Output execution time echo '<br>This page was created in '.$totaltime.' seconds'; ?>
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.26, 7.3.0 - 7.3.13, 7.4.0 - 7.4.1
Warning: require(): open_basedir restriction in effect. File(phpQuery.php) is not within the allowed path(s): (/tmp:/in:/etc) in /in/8r7rg on line 6 Warning: require(phpQuery.php): failed to open stream: Operation not permitted in /in/8r7rg on line 6 Fatal error: require(): Failed opening required 'phpQuery.php' (include_path='.:') in /in/8r7rg on line 6
Process exited with code 255.

preferences:
51.85 ms | 407 KiB | 5 Q