1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
memcacheconnectionconfigurator.php
См. документацию.
1<?php
2
4
7
9{
10 protected array $config;
11 protected array $servers = [];
12
16 public function __construct($config)
17 {
18 if (!extension_loaded('memcache'))
19 {
20 throw new NotSupportedException('memcache extension is not loaded.');
21 }
22
23 $this->config = $config;
24 $this->addServers($this->getConfig());
25 }
26
27 protected function addServers($config): MemcacheConnectionConfigurator
28 {
29 $servers = $config['servers'] ?? [];
30
31 if (isset($config['host'], $config['port']))
32 {
33 array_unshift($servers, [
34 'host' => $config['host'],
35 'port' => $config['port'],
36 ]);
37 }
38
39 foreach ($servers as $server)
40 {
41 if (!isset($server['weight']) || $server['weight'] <= 0)
42 {
43 $server['weight'] = 1;
44 }
45
46 $this->servers[] = [
47 'host' => $server['host'] ?? 'localhost',
48 'port' => $server['port'] ?? '11211',
49 'weight' => $server['weight'],
50 ];
51 }
52
53 return $this;
54 }
55
56 public function getConfig(): array
57 {
58 return $this->config;
59 }
60
61 public function createConnection(): ?\Memcache
62 {
63 if (!$this->servers)
64 {
65 throw new NotSupportedException('Empty server list to memcache connection.');
66 }
67
68 $connectionTimeout = $this->getConfig()['connectionTimeout'] ?? 1;
69 $persistent = $this->getConfig()['persistent'] ?? true;
70
71 $connection = new \Memcache();
72
73 $result = false;
74 if (count($this->servers) === 1)
75 {
76 ['host' => $host, 'port' => $port] = $this->servers[0];
77 if ($persistent)
78 {
79 $result = $connection->pconnect($host, $port, $connectionTimeout);
80 }
81 else
82 {
83 $result = $connection->connect($host, $port, $connectionTimeout);
84 }
85 }
86 else
87 {
88 foreach ($this->servers as $server)
89 {
90 $success = $connection->addServer(
91 $server['host'],
92 $server['port'],
93 $persistent,
94 $server['weight'],
95 $connectionTimeout
96 );
97
98 if ($success)
99 {
101 }
102 }
103 }
104
105 if (!$result)
106 {
107 $error = error_get_last();
108 if (isset($error["type"]) && $error["type"] === E_WARNING)
109 {
110 $exception = new \ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']);
112 $exceptionHandler = $application->getExceptionHandler();
113 $exceptionHandler->writeToLog($exception);
114 }
115 }
116
117 return $result? $connection : null;
118 }
119}
$connection
Определения actionsdefinitions.php:38
static getInstance()
Определения application.php:98
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
$success
Определения mail_entry.php:69
$application
Определения bitrix.php:23
$host
Определения mysql_to_pgsql.php:32
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$error
Определения subscription_card_product.php:20