1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
queue.php
См. документацию.
1<?php
2
9
10namespace Bitrix\Main\Web\Http\Curl;
11
12use Bitrix\Main\Web\Http;
13use Bitrix\Main\Web\HttpDebug;
14
15class Queue extends Http\Queue
16{
18 protected array $promises = [];
19 protected \CurlMultiHandle $handle;
20
21 public function __construct()
22 {
23 parent::__construct();
24
25 $this->handle = curl_multi_init();
26 }
27
28 public function __destruct()
29 {
30 curl_multi_close($this->handle);
31 }
32
39 public function add(Promise $promise): void
40 {
41 $this->promises[$promise->getId()] = $promise;
42
43 curl_multi_add_handle($this->handle, $promise->getHandler()->getHandle());
44 }
45
46 protected function delete(string $promiseId): void
47 {
48 curl_multi_remove_handle($this->handle, $this->promises[$promiseId]->getHandler()->getHandle());
49
50 unset($this->promises[$promiseId]);
51 }
52
56 public function wait(?Http\Promise $targetPromise = null): array
57 {
58 $processedPromises = [];
59
60 if (empty($this->promises))
61 {
62 return $processedPromises;
63 }
64
65 do
66 {
67 $fetchBody = true;
68
69 try
70 {
71 $status = curl_multi_exec($this->handle, $active);
72 }
73 catch (SkipBodyException)
74 {
75 $fetchBody = false;
76 }
77
78 $info = curl_multi_info_read($this->handle);
79
80 if ($info !== false)
81 {
82 $promiseId = spl_object_hash($info['handle']);
83
84 $promise = $this->promises[$promiseId];
85 $handler = $promise->getHandler();
86
87 if (!$fetchBody)
88 {
89 // we don't want a body, just fulfil a promise with response headers
90 $promise->fulfill($handler->getResponse());
91 }
92 elseif ($info['result'] === CURLE_OK)
93 {
94 $response = $handler->getResponse();
95
96 if ($handler->getDebugLevel() & HttpDebug::RESPONSE_BODY)
97 {
98 $handler->log($response->getBody(), HttpDebug::RESPONSE_BODY);
99 }
100
101 // need to ajust the response headers (PSR-18)
102 $response->adjustHeaders();
103
104 $promise->fulfill($response);
105
106 $handler->logDiagnostics();
107 }
108 else
109 {
110 $error = curl_error($info['handle']);
111
112 $promise->reject(new Http\NetworkException($promise->getRequest(), $error));
113
114 $handler->getLogger()?->error($error . "\n");
115 }
116
117 // job done, the promise is fullfilled or rejected
118 $processedPromises[] = $promise;
119
120 $this->delete($promiseId);
121
122 if ($targetPromise && $promiseId === $targetPromise->getId())
123 {
124 // we were waiting for the specific promise
125 return $processedPromises;
126 }
127 }
128 }
129 while ($status === CURLM_CALL_MULTI_PERFORM || $active);
130
131 return $processedPromises;
132 }
133}
add(Promise $promise)
Определения queue.php:39
wait(?Http\Promise $targetPromise=null)
Определения queue.php:56
array $promises
Определения queue.php:18
CurlMultiHandle $handle
Определения queue.php:19
const RESPONSE_BODY
Определения httpdebug.php:18
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$status
Определения session.php:10
if($NS['step']==6) if( $NS[ 'step']==7) if(COption::GetOptionInt('main', 'disk_space', 0) > 0) $info
Определения backup.php:924
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$response
Определения result.php:21
$error
Определения subscription_card_product.php:20