Now that many people have picked up PocketMine-MP plugin development, and PHP development in general, I would like to make a proposal. For those large applications that require large amounts of read and write, can we all please begin to use a database engine. For this objective, SQLite would be the perfect database to use. SQLite is precompiled with the same PHP binary used by all PocketMine servers. It is used by all servers, mainly because PocketMine uses SQLite. Here is an example plugin using SQLite. It is a simple VoteKick plugin that kicks a user after he/she has accumulated a certain amount of votes. Here is the code: PHP: <?php/*__PocketMine Plugin__name=VoteKickversion=0.0.1author=humerusjapiversion=10class=vk*/class vk implements Plugin { private $api; public function __construct(ServerAPI $api, $server = false) { $this->api = $api; } public function initialize() { $this->db = new SQLite3($this->api->plugin->configPath($this) . "vk.sq3"); $this->db->exec("CREATE TABLE IF NOT EXISTS users (username TEXT, votes TEXT);"); $this->db->exec("CREATE TABLE IF NOT EXISTS config (votestokick INT);"); $this->db->exec("INSERT INTO config (votestokick) VALUES (5);"); } public function init() { $this->initialize(); $this->api->console->register("vote-kick", "<user> <reason>", array($this, "commandHandler"), 1); $this->api->addHandler("player.join", array($this, "eventHandler"), 1); $this->api->console->alias("vk", "vote-kick"); $this->api->ban->cmdwhitelist("vote-kick"); } public function __destruct() { } public function commandHandler($cmd, $params, $issuer){ $config = $this->db->query("SELECT * FROM config"); $config = $config->fetchArray(); switch($cmd) { case "vote-kick": $player = $this->api->player->get($params[0]); if(!($player instanceof Player)){ $issuer->sendChat("[VoteKick] Player does not exist!"); break; } $vkinfo = $this->db->prepare("SELECT * FROM users WHERE username = :user"); $vkinfo->bindValue(":user", $player->username); $vkinfo = $vkinfo->execute(); $vkinfo = $vkinfo->fetchArray(); if(strpos($vkinfo['votes'], $issuer->username) != false){ $issuer->sendChat("[VoteKick] You have already voted!"); break; }elseif((count(explode(" ", $vkinfo['votes'])) + 1) === $config[0]){ $player->close("You were vote kicked!"); } $update = $this->db->prepare("UPDATE users SET votes = :votes WHERE username = :user"); $update->bindValue(":votes", ($vkinfo['votes']." ".$issuer->username)); $update->bindValue(":user", $player->username); $update->execute(); $vkinfo = $this->db->prepare("SELECT * FROM users WHERE username = :user"); $vkinfo->bindValue(":user", $player->username); $vkinfo = $vkinfo->execute(); $vkinfo = $vkinfo->fetchArray(); $this->api->chat->broadcast("[VoteKick] ".$issuer->username." has started a vote to kick"); $this->api->chat->broadcast("[VoteKick] ".$player->username.". ".($config[0] - (count(explode(" ", $vkinfo['votes']))-1))." votes needed to kick user."); break; } } public function eventHandler($data, $event){ switch($event) { case "player.join": $clear = $this->db->prepare("UPDATE users SET votes = :votes WHERE username = :username"); $clear->bindValue(":username", $data->username); $clear->bindValue(":votes", ""); $clear->execute(); $vkinfo = $this->db->prepare("SELECT * FROM users WHERE username = :user"); $vkinfo->bindValue(":user", $data->username); $vkinfo = $vkinfo->execute(); if(!$vkinfo->fetchArray()){ console("User not found"); $insert = $this->db->prepare("INSERT INTO users (username, votes) VALUES (:username, :votes)"); $insert->bindValue(":username", $data->username); $insert->bindValue(":votes", ""); $insert->execute(); } break; } }} Take a look at this example plugin. Initializing SQLite is extremely simple, and everything can be entered into the database without needing too much work. SQLite is the perfect thing for this task since it is fast, lightweight and can be used in most, if not all, situations. If you are aspiring to become a greater developer, SQLite will also help you with dealing with database engines such as MySQL, which is used in most websites today. Please take a look at this proposal, and let me know what you think. It is for the sake of the community, to create better and more effective plugins. Thank you and have fun, Humerus
Databases are not always as fast as you may think. If you want to use a database, then load the files into a database in the memory and store the database into the files when the server shuts down. Otherwise the database needs to read and write to its file every time you do a query.
How to store the database into the files? Sorry for bumping but... it turned out that this thread is the best place to ask, even better than starting a new thread.