3 A merry configuration container.
12 "flags" => pq\Connection::PERSISTENT
16 "hosts" => ["10.0.1.1", "10.0.1.2", "10.0.1.3"]
20 printf("Using database: '%s'\n", $config->db->dsn);
21 printf("Using cache cluster: '%s'\n", $config->cache->pid);
24 "db" => function($conf) {
25 return new pq\Connection($conf->dsn, $conf->flags);
27 "cache" => function($conf) {
28 $cache = new Memcached($conf->pid);
29 foreach ($conf->{$conf->pid}->hosts as $host) {
30 $cache->addServer($host);
37 extract($config->toArray());
39 if (!($q1 = $cache->get("q1"))) {
40 $result = $db->exec("SELECT 1");
41 $cache->set("q1", $q1 = $result->fetchAll());
49 $array = parse_ini_string('
52 db.flags = 2 ;pq\Connection::PERSISTENT
53 cache.pid = "cluster1"
54 cache.cluster1.hosts[] = "10.0.1.1"
55 cache.cluster1.hosts[] = "10.0.1.2"
56 cache.cluster1.hosts[] = "10.0.1.3"
57 [production : localhost]
61 $config = new Config($array, getenv("APPLICATION_ENV"));
62 $flags = \RecursiveTreeIterator::BYPASS_CURRENT;
63 foreach (new \RecursiveTreeIterator($config, $flags) as $key => $val ) {
64 printf("%s: %s\n", $key, ($val instanceof Config) ? "" : $val);