我已經搜索EVERYWHERE爲此,我有很多問題,但我不認爲這是與實際代碼的問題。 基本上這段代碼在兩個獨立的線程中啓動套接字服務器(登錄和遊戲),我基本上從非線程版本轉換了這段代碼,但我一直無法得到線程的這個工作。PHP Threading SimpleXMLElement
include "socket.php";
include "dep.php";
class Server extends Thread {
public $server;
public $config;
public function __construct($type){
//$this->config = (string)$type;
$this->run2($type);
$this->run();
}
public function run(){
while(true){
$this->server->loop();
}
}
public function run2($config){
$this->server = new sokserv($config);
$this->server->init();
//while(true){
// $this->server->loop();
//}
}
}
$login = new Server('Config/config.xml');
$game = new Server("Config/config2.xml");
The error received is
Fatal error: Uncaught exception 'Exception' with message 'Serialization of 'SimpleXMLElement' is not allowed' in C:\Users\=\Desktop\Test\Start.php:19
Stack trace:
#0 C:\Users\=\Desktop\Test\Start.php(19): Server->run2()
#1 C:\Users\=\Desktop\Test\Start.php(10): Server->run2('Config/config.x...')
#2 C:\Users\=\Desktop\Test\Start.php(26): Server->__construct('Config/config.x...')
#3 {main}
thrown in C:\Users\=\Desktop\Test\Start.php on line 19
但是,恢復到舊的代碼工作正常。 sokserv的第一位(我刪除了一些公共瓦爾,因爲它們包含的個人信息)
class sokserv
{
public $ip;
public $port;
public $users = array();
public $config;
public $mysql;
private $socket;
public function __construct($config = "Config/config.xml")
{
$this->readConfig($config);
}
public function readConfig($file)
{
if (!file_exists($file))
die("Could not find config");
$this->config = simplexml_load_file($file);
}
如果你想這是XML:
<server>
<port>6112</port>
<ip>0</ip>
<mysql>
<host>127.0.0.1</host>
<username>root</username>
<dbname></dbname>
<password></password>
<table></table>
</mysql>
</server>
請分享sockserv的實現或源代碼鏈接。我想你可能需要將config var轉換爲數組。 –
我無法分享sokserv課程,因爲它太大並且包含個人信息,但我可以分享涉及配置的前幾個位。 – user2601312
是的,請您這樣做,你可能只是一個構造函數 –