31 if (!is_array($arSelect))
35 if (
count($arSelect) < 1)
49 if (!is_array($arOrder))
55 foreach ($arOrder as $strColumn => $strDirection)
57 $strColumn = mb_strtoupper($strColumn);
58 $strDirection = mb_strtoupper($strDirection) ===
'ASC' ?
'ASC' :
'DESC';
59 if ($strColumn ===
'ID')
61 $arSelect[] = $strColumn;
62 $arQueryOrder[$strColumn] = $strColumn .
' ' . $strDirection;
67 foreach ($arSelect as $strColumn)
69 $strColumn = mb_strtoupper($strColumn);
77 case 'PAGES_PER_SECOND':
78 case 'PAGE_EXEC_TIME':
79 case 'PAGE_RESP_TIME':
80 $arQuerySelect[$strColumn] =
'p.' . $strColumn;
84 if (
count($arQuerySelect) < 1)
86 $arQuerySelect = [
'ID' =>
'p.ID'];
93 'FIELD_NAME' =>
'p.ID',
94 'FIELD_TYPE' =>
'int',
104 $strQueryWhere = $obQueryWhere->GetQuery(
$arFilter);
106 $bDistinct = $obQueryWhere->bDistinctReqired;
109 SELECT ' . ($bDistinct ?
'DISTINCT' :
'') .
'
110 ' . implode(
', ', $arQuerySelect) .
'
113 ' . $obQueryWhere->GetJoins() .
'
120 ' . $strQueryWhere .
'
124 if (
count($arQueryOrder) > 0)
128 ' . implode(
', ', $arQueryOrder) .
'
132 return $DB->Query($strSql,
false,
'', [
'fixed_connection' =>
true]);
139 $strRequest =
'GET ' .
$url .
" HTTP/1.0\r\n";
140 $strRequest .=
"User-Agent: BitrixSMCluster (thread #thread#)\r\n";
141 $strRequest .=
"Accept: */*\r\n";
142 $strRequest .=
'Host: ' .
$host .
"\r\n";
143 $strRequest .=
"Accept-Language: en\r\n";
145 $socket_timeout = intval(
$arOptions[
'socket_timeout'] ?? 0);
146 if ($socket_timeout <= 0)
148 $socket_timeout = 20;
151 $rw_timeout = intval(
$arOptions[
'rw_timeout'] ?? 0);
152 if ($rw_timeout <= 0)
157 $iteration_timeout = intval(
$arOptions[
'iteration_timeout'] ?? 0);
158 if ($iteration_timeout <= 0)
160 $iteration_timeout = 30;
173 $end =
$start + $iterations;
174 $end_after_end =
$start + $iteration_timeout;
181 $arPageExecTime = [];
182 $arResponseTime = [];
183 while (microtime(1) < $end)
186 if (
count($arConnections) < $threads)
189 for ($j = 0; $j < $threads; $j++)
191 if (!isset($arConnections[$j]))
193 $arStartTimes[$j] = microtime(1);
194 $socket = fsockopen($proto .
$host, $port, $errno, $errstr, $socket_timeout);
197 $request = str_replace(
'#thread#', $j, $strRequest);
198 if (isset($arCookie[$j]))
200 $request .=
'Cookie: ' . implode(
';', $arCookie[$j]) .
"\r\n";
204 stream_set_blocking($socket,
true);
205 stream_set_timeout($socket, $rw_timeout);
207 stream_set_blocking($socket,
false);
208 $arConnections[$j] = $socket;
213 $arConnections[$j] =
false;
222 foreach ($arConnections as $j => $socket)
228 $arResponseTime[] = microtime(1) - $arStartTimes[$j];
230 unset($arConnections[$j]);
234 $line = fgets($socket);
237 if (preg_match(
'/^Set-Cookie: (.*?)=(.*?);/', $line, $match))
239 $arCookie[$j][$match[1]] = $match[1] .
'=' . $match[2];
241 elseif (preg_match(
'/<span id="bx_main_exec_time">(\\d+\\.\\d+)<\\/span>/', $line, $match))
243 $arPageExecTime[] = $match[1];
245 elseif (preg_match(
'/^HTTP\\/\\d+\\.\\d+\\s+(\\d+)\\s/', $line, $match))
247 if ($match[1] !==
'200')
252 elseif (preg_match(
'/^Status:\\s+(\\d+)\\s/', $line, $match))
254 if ($match[1] !==
'200')
266 while (
count($arConnections) > 0)
269 foreach ($arConnections as $j => $socket)
275 $arResponseTime[] = microtime(1) - $arStartTimes[$j];
277 unset($arConnections[$j]);
281 $line = fgets($socket);
284 if (preg_match(
'/<span id="bx_main_exec_time">(\\d+\\.\\d+)<\\/span>/', $line, $match))
286 $arPageExecTime[] = $match[1];
288 elseif (preg_match(
'/^HTTP\\/\\d+\\.\\d+\\s+(\\d+)\\s/', $line, $match))
290 if ($match[1] !==
'200')
295 elseif (preg_match(
'/^Status:\\s+(\\d+)\\s/', $line, $match))
297 if ($match[1] !==
'200')
307 unset($arConnections[$j]);
309 if (microtime(1) > $end_after_end)
314 if (microtime(1) > $end_after_end)
321 '~TIMESTAMP_X' =>
$DB->CurrentTimeFunction(),
322 'THREADS' => $threads,
325 'PAGES_PER_SECOND' => $Pages / $iterations,
326 'PAGE_EXEC_TIME' =>
count($arPageExecTime) ? array_sum($arPageExecTime) /
count($arPageExecTime) : 0,
327 'PAGE_RESP_TIME' =>
count($arResponseTime) ? array_sum($arResponseTime) /
count($arResponseTime) : 0,