Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 1... Línea 1...
1
<?php
1
<?php
Línea 2... Línea 2...
2
 
2
 
Línea -... Línea 3...
-
 
3
namespace GuzzleHttp\Handler;
3
namespace GuzzleHttp\Handler;
4
 
4
 
5
use Closure;
5
use GuzzleHttp\Promise as P;
6
use GuzzleHttp\Promise as P;
6
use GuzzleHttp\Promise\Promise;
7
use GuzzleHttp\Promise\Promise;
7
use GuzzleHttp\Promise\PromiseInterface;
8
use GuzzleHttp\Promise\PromiseInterface;
Línea 13... Línea 14...
13
 *
14
 *
14
 * When using the CurlMultiHandler, custom curl options can be specified as an
15
 * When using the CurlMultiHandler, custom curl options can be specified as an
15
 * associative array of curl option constants mapping to values in the
16
 * associative array of curl option constants mapping to values in the
16
 * **curl** key of the provided request options.
17
 * **curl** key of the provided request options.
17
 *
18
 *
18
 * @property resource|\CurlMultiHandle $_mh Internal use only. Lazy loaded multi-handle.
-
 
19
 *
-
 
20
 * @final
19
 * @final
21
 */
20
 */
22
#[\AllowDynamicProperties]
-
 
23
class CurlMultiHandler
21
class CurlMultiHandler
24
{
22
{
25
    /**
23
    /**
26
     * @var CurlFactoryInterface
24
     * @var CurlFactoryInterface
27
     */
25
     */
Línea 54... Línea 52...
54
    /**
52
    /**
55
     * @var array<mixed> An associative array of CURLMOPT_* options and corresponding values for curl_multi_setopt()
53
     * @var array<mixed> An associative array of CURLMOPT_* options and corresponding values for curl_multi_setopt()
56
     */
54
     */
57
    private $options = [];
55
    private $options = [];
Línea -... Línea 56...
-
 
56
 
-
 
57
    /** @var resource|\CurlMultiHandle */
-
 
58
    private $_mh;
58
 
59
 
59
    /**
60
    /**
60
     * This handler accepts the following options:
61
     * This handler accepts the following options:
61
     *
62
     *
62
     * - handle_factory: An optional factory  used to create curl handles
63
     * - handle_factory: An optional factory  used to create curl handles
Línea 77... Línea 78...
77
        } else {
78
        } else {
78
            $this->selectTimeout = 1;
79
            $this->selectTimeout = 1;
79
        }
80
        }
Línea 80... Línea 81...
80
 
81
 
-
 
82
        $this->options = $options['options'] ?? [];
-
 
83
 
-
 
84
        // unsetting the property forces the first access to go through
-
 
85
        // __get().
81
        $this->options = $options['options'] ?? [];
86
        unset($this->_mh);
Línea 82... Línea 87...
82
    }
87
    }
83
 
88
 
84
    /**
89
    /**
Línea 153... Línea 158...
153
                    );
158
                    );
154
                }
159
                }
155
            }
160
            }
156
        }
161
        }
Línea -... Línea 162...
-
 
162
 
-
 
163
        // Run curl_multi_exec in the queue to enable other async tasks to run
-
 
164
        P\Utils::queue()->add(Closure::fromCallable([$this, 'tickInQueue']));
157
 
165
 
158
        // Step through the task queue which may add additional requests.
166
        // Step through the task queue which may add additional requests.
Línea 159... Línea 167...
159
        P\Utils::queue()->run();
167
        P\Utils::queue()->run();
160
 
168
 
161
        if ($this->active && \curl_multi_select($this->_mh, $this->selectTimeout) === -1) {
169
        if ($this->active && \curl_multi_select($this->_mh, $this->selectTimeout) === -1) {
162
            // Perform a usleep if a select returns -1.
170
            // Perform a usleep if a select returns -1.
163
            // See: https://bugs.php.net/bug.php?id=61141
171
            // See: https://bugs.php.net/bug.php?id=61141
Línea 164... Línea 172...
164
            \usleep(250);
172
            \usleep(250);
-
 
173
        }
-
 
174
 
-
 
175
        while (\curl_multi_exec($this->_mh, $this->active) === \CURLM_CALL_MULTI_PERFORM) {
Línea 165... Línea 176...
165
        }
176
            // Prevent busy looping for slow HTTP requests.
166
 
177
            \curl_multi_select($this->_mh, $this->selectTimeout);
Línea 167... Línea 178...
167
        while (\curl_multi_exec($this->_mh, $this->active) === \CURLM_CALL_MULTI_PERFORM);
178
        }
-
 
179
 
-
 
180
        $this->processMessages();
-
 
181
    }
-
 
182
 
-
 
183
    /**
-
 
184
     * Runs \curl_multi_exec() inside the event loop, to prevent busy looping
-
 
185
     */
-
 
186
    private function tickInQueue(): void
-
 
187
    {
-
 
188
        if (\curl_multi_exec($this->_mh, $this->active) === \CURLM_CALL_MULTI_PERFORM) {
-
 
189
            \curl_multi_select($this->_mh, 0);
168
 
190
            P\Utils::queue()->add(Closure::fromCallable([$this, 'tickInQueue']));
169
        $this->processMessages();
191
        }
170
    }
192
    }
171
 
193
 
172
    /**
194
    /**