54 list($usec, $sec) = explode(
" ", microtime());
56 $uniqid = mb_substr(base_convert($sec.mb_substr($usec, 2), 10, 36), 0, 16);
58 if (mb_strlen($uniqid) < 16)
60 $uniqid .= Random::getString(16 - mb_strlen($uniqid));
70 return '\\'.__METHOD__.
'();';
75 $r = static::getList(array(
76 'order' => array(
'ID' =>
'ASC'),
80 while ($row = $r->fetch())
82 $rows[$row[
'ID']] = array(
83 'type' => $row[
'TYPE'],
84 'data' => $row[
'DATA']
91 $totalCount = static::getCount();
92 $queueSize = $totalCount > $limit ? $totalCount-$limit : 0;
95 $dataSizeLimit = 45000;
98 $dataSize = mb_strlen(base64_encode(json_encode(array_values($rows))));
103 if ($dataSize > $dataSizeLimit)
105 $reducedRows = array();
107 foreach ($rows as $id => $row)
109 $rowSize = mb_strlen(base64_encode(json_encode(array_values($row))));
110 $reducedDataSize = mb_strlen(base64_encode(json_encode(array_values($reducedRows))));
112 if ($rowSize > $dataSizeLimit)
117 elseif (!empty($reducedRows) && ($reducedDataSize + $rowSize) > $dataSizeLimit)
124 $reducedRows[$id] = $row;
128 $rows = $reducedRows;
134 $data = \http_build_query(array(
137 'ad[cd][value]' => base64_encode(json_encode(array_values($rows))),
138 'ad[cd][queue]' => $queueSize
141 $f = fsockopen(
'bitrix.info', 80, $errno, $errstr, 3);
145 $out =
"POST /bx_stat HTTP/1.1\r\n";
146 $out .=
"Host: bitrix.info\r\n";
147 $out .=
"Content-type: application/x-www-form-urlencoded\r\n";
148 $out .=
"Content-length: ".mb_strlen($data) .
"\r\n";
149 $out .=
"User-Agent: Bitrix Stats Counter\r\n";
150 $out .=
"Connection: Close\r\n";
152 $out .= $data .
"\r\n\r\n";
160 $response .= fgets($f, 128);
166 if(mb_strpos($response,
'200 OK'))
168 $toDelete = array_merge($toDelete, array_keys($rows));
174 foreach ($toDelete as $id)
180 return '\\'.__METHOD__.
'();';