Fixed a weird, random, pthreads-caused crash

This commit is contained in:
Shoghi Cervantes Pueyo 2013-04-09 17:21:49 +02:00
parent 533b175b66
commit 79ca735fb0
3 changed files with 25 additions and 3 deletions

View File

@ -33,6 +33,6 @@ require_once(FILE_PATH."/src/dependencies.php");
/***REM_END***/
$server = new ServerAPI();
$server->run();
$server->start();
exit(0);

View File

@ -28,14 +28,20 @@ the Free Software Foundation, either version 3 of the License, or
class ServerAPI{
var $restart = false;
private static $serverRequest = false;
private $asyncCalls = array();
private $server;
private $config;
private $apiList = array();
private $asyncCnt = 0;
public static function request(){
return self::$serverRequest;
}
public function start(){
return $this->run();
}
public function run(){
$this->load();
return $this->init();
@ -223,13 +229,29 @@ class ServerAPI{
$this->server->loadEntities();
}
public function async(callable $callable, $params = array()){
$cnt = $this->asyncCnt++;
$this->asyncCalls[$cnt] = new Async($callable, $params);
return $cnt;
}
public function getAsync($id){
if(!isset($this->asyncCalls[$id])){
return false;
}
$ob = $this->asyncCalls[$id];
$this->asyncCalls[$id] = null;
unset($this->asyncCalls[$id]);
return $ob;
}
public function sendUsage(){
console("[INTERNAL] Sending usage data...", true, true, 3);
$plist = "";
foreach($this->plugin->getList() as $p){
$plist .= str_replace(array(";", ":"), "", $p["name"]).":".str_replace(array(";", ":"), "", $p["version"]).";";
}
Async::call("Utils::curl_post", array(
$this->async("Utils::curl_post", array(
0 => "http://stats.pocketmine.net/usage.php",
1 => array(
"serverid" => $this->server->serverID,

View File

@ -35,7 +35,7 @@ define("BIG_ENDIAN", 0x00);
define("LITTLE_ENDIAN", 0x01);
define("ENDIANNESS", (pack("d", 1) === "\77\360\0\0\0\0\0\0" ? BIG_ENDIAN:LITTLE_ENDIAN));
class Utils extends Thread{
class Utils{
public static $online = true;
public function run(){