3v4l.org

run code in 300+ PHP versions simultaneously
<?php require 'vendor/autoload.php'; use Dotenv\Dotenv; $dotenv = Dotenv::createImmutable(__DIR__); $dotenv->load(); $host = $_ENV['DB_HOST']; $name = $_ENV['DB_NAME']; $db = pg_connect("host=$host dbname=$name"); if (!$db) { echo "Error connection to database"; } echo "Connected to $name successfully \n"; $sql = file_get_contents('init_db.sql'); pg_query($db, $sql); ?> This is the .sql file that gets loaded and populates the database -- init_db.sql DROP TABLE IF EXISTS users; CREATE TABLE IF NOT EXISTS users ( id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, surname VARCHAR(50) NOT NULL, password VARCHAR(255) NOT NULL, email VARCHAR(100) NOT NULL UNIQUE, phone VARCHAR(20) NOT NULL, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -- Insert initial data INSERT INTO users (name, surname, password, email, phone) VALUES ('admin', 'admin', '$2y$10$oEpwSflquB9WyTSVkHj8HupkxygaepInmricYtoNTTAGh23iPOK3.%', 'admin@example.com', '123123123'), ('John', 'Doe', '$2y$10$oEpwSflquB9WyTSVkHj8HupkxygaepInmricYtoNTTAGh23iPOK3.%', 'user@example.com', '123123123'); The password hash was gotten by using "password_hash('123', PASSWORD_DEFAULT);" and copying the output // The login page that reads the DB password and checks it <?php require_once '../vendor/autoload.php'; use Dotenv\Dotenv; // NOTE: Maybe there is a better way to do this but I don't know about it. $dotenv = Dotenv::createImmutable(__DIR__ . '/../'); $dotenv->load(); $dbName = $_ENV['DB_NAME']; session_start(); if (isset($_POST) && isset($_POST['email']) && isset($_POST['password'])) { $email = $_POST['email']; $db = pg_connect("dbname=$dbName"); if (!$db) { die('Connection to DB failed: ' . pg_last_error()); } $res = pg_query_params($db, "SELECT u.password, u.id, u.email FROM users u WHERE u.email=$1", [$email]); if (!$res) { die('Query failed: ' . pg_last_error()); } $row = pg_fetch_assoc($res); if ($row) { $password = $_POST['password']; if (password_verify($password, $row['password'])) { $_SESSION['loggedin'] = true; $_SESSION['id'] = $row['id']; $_SESSION['email'] = $row['email']; header('Location: dashboard.php'); } else { echo 'Wrong password'; } } else { echo 'User not found'; } pg_free_result($res); pg_close($db); } ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Login</title> </head> <body> <form action="login.php" method="POST"> <label for="email">E-mail:</label> <input type="email" id="email" name="email"> <label for="password">Password:</label> <input type="password" id="password" name="password"> <button type="submit">login</button> </form> </body> </html>

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.90.0400.00626.77
8.3.80.0350.00326.77
8.3.70.0230.01026.77
8.3.60.0370.00926.77
8.3.50.0360.01126.77
8.3.40.0360.01026.77
8.3.30.0300.00726.77
8.3.20.0270.01326.77
8.3.10.0360.00926.77
8.3.00.0330.01026.77
8.2.210.0190.01926.77
8.2.200.0310.00626.77
8.2.190.0270.00526.77
8.2.180.0280.00326.77
8.2.170.0300.01326.77
8.2.160.0340.00826.77
8.2.150.0320.01126.77
8.2.140.0330.01126.77
8.2.130.0380.00326.77
8.2.120.0320.01026.77
8.2.110.0350.01026.77
8.2.100.0430.00026.77
8.2.90.0420.00026.77
8.2.80.0290.01326.77
8.2.70.0300.01426.77
8.2.60.0430.00026.77
8.2.50.0350.00726.77
8.2.40.0370.00326.77
8.2.30.0260.01326.77
8.2.20.0320.00326.77
8.2.10.0230.00826.77
8.2.00.0220.00326.77
8.1.290.0180.00426.77
8.1.280.0210.00726.77
8.1.270.0350.00626.77
8.1.260.0270.01526.77
8.1.250.0280.01226.77
8.1.240.0370.00426.77
8.1.230.0350.00326.77
8.1.220.0280.00626.77
8.1.210.0300.00826.77
8.1.200.0280.01026.77
8.1.190.0260.01126.77
8.1.180.0210.01626.77
8.1.170.0290.00826.77
8.1.160.0260.01126.77
8.1.150.0330.00426.77
8.1.140.0190.01526.77
8.1.130.0240.00726.77
8.1.120.0320.00726.77
8.1.110.0280.01426.77
8.1.100.0300.00926.77
8.1.90.0310.00726.77
8.1.80.0330.00426.77
8.1.70.0250.01326.77
8.1.60.0350.00526.77
8.1.50.0400.00026.77
8.1.40.0240.01826.77
8.1.30.0290.01326.77
8.1.20.0350.00626.77
8.1.10.0230.01926.77
8.1.00.0340.00726.77

preferences:
138.97 ms | 1421 KiB | 7 Q