Zend TSRM , ; - . , , . pthreads , , .
, , PHP, pthreads , , . , , pthreads , - . , SimpleXML - .
, , , pthreads, . , pthreads, API , , , , .
, , , pthreads:
<?php
class Config extends Stackable {
public function __construct($xml, &$objects) {
if ($xml instanceof SimpleXMLElement) {
foreach ($xml as $key => $value)
$this[$key] = (string) $value;
} else {
foreach (simplexml_load_string(
$xml) as $key => $value) {
if ($value->children()) {
$this[$key] = new Config($value, $objects);
} else $this[$key] = (string) $value;
}
}
$objects[] = $this;
}
public function run() {}
}
class Test extends Thread {
protected $config;
public function __construct(Config $config) {
$this->config = $config;
}
public function run() {
printf("%d settings:\n", count($this->config));
foreach ($this->config as $key => $data) {
if (count($data) > 1) {
printf(
"\t%s, %d settings:\n", $key, count($data));
foreach ($data as $name => $value) {
printf("\t\t%s = %s\n", $name, $value);
}
} else printf("\t%s = %s\n", $key, $data);
}
printf("\n");
printf(
"Host: %s:%d\n",
$this->config->ip,
$this->config->port);
printf(
"MySQL: %s@%s?database=%s&password=%s&table=%s\n",
$this->config->mysql->username,
$this->config->mysql->host,
$this->config->mysql->dbname,
$this->config->mysql->password,
$this->config->mysql->table);
}
}
$xml = <<<XML
<server>
<port>6112</port>
<ip>some.ip</ip>
<mysql>
<host>127.0.0.1</host>
<username>root</username>
<dbname>somedb</dbname>
<password>somepass</password>
<table>sometable</table>
</mysql>
</server>
XML;
$objects = [];
$config = new Config($xml, $objects);
$thread = new Test($config);
$thread->start();
$thread->join();
?>
:
3 settings:
port = 6112
ip = some.ip
mysql, 5 settings:
host = 127.0.0.1
username = root
dbname = somedb
password = somepass
table = sometable
Host: some.ip:6112
MySQL: root@127.0.0.1?database=somedb&password=somepass&table=sometable
XML- [format], , XML , .
Config XML.
Config , , / .
, , , , , , , , , , , .
: https://gist.github.com/krakjoe/6437782