Right now im using a task which does not work and is probably causing lag. is there something I have to do because when players try to access the database the server crashes.
You can make a task that keeps pinging your Database PHP: class MySQLPingTask extends Task { /** * MySQLPingTask constructor. * @param Main $plugin */ public function __construct(Main $plugin){ $this->plugin = $plugin; } /** * @param int $currentTick */ public function onRun(int $currentTick){ $plugin = $this->plugin; if(!$plugin->getDb()->ping()){ $plugin->openProvider(); } }}
I figured out myself last night and this is probably not the best way. What im doing is making mySQL do a query every 25 seconds. if this way is bad show me a better optimized way also I have not tried the one above. My Code: Code: public function onRun($currentTick) { $this->runTimes--; if($this->runTimes == 0) { $this->timeOutCheck(); } } public function timeOutCheck() { $this->plugin->sql->query("SELECT * FROM users WHERE name = 'timeOut"); $this->runTimes = 25; $this->plugin->getScheduler()->cancelTask($this->getTaskId()); $this->plugin->getScheduler()->scheduleDelayedRepeatingTask($this, 25, 20); }