PocketMine-MP 5.21.3 git-fcef015f32c0b0709cfd4d6f1b3c32f484b25bde
Loading...
Searching...
No Matches
BulkCurlTask.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\scheduler;
25
29use function igbinary_serialize;
30use function igbinary_unserialize;
31
37class BulkCurlTask extends AsyncTask{
38 private const TLS_KEY_COMPLETION_CALLBACK = "completionCallback";
39
40 private string $operations;
41
52 public function __construct(array $operations, \Closure $onCompletion){
53 $this->operations = igbinary_serialize($operations);
54 $this->storeLocal(self::TLS_KEY_COMPLETION_CALLBACK, $onCompletion);
55 }
56
57 public function onRun() : void{
62 $operations = igbinary_unserialize($this->operations);
63 $results = [];
64 foreach($operations as $op){
65 try{
66 $results[] = Internet::simpleCurl($op->getPage(), $op->getTimeout(), $op->getExtraHeaders(), $op->getExtraOpts());
67 }catch(InternetException $e){
68 $results[] = $e;
69 }
70 }
71 $this->setResult($results);
72 }
73
74 public function onCompletion() : void{
79 $callback = $this->fetchLocal(self::TLS_KEY_COMPLETION_CALLBACK);
81 $results = $this->getResult();
82 $callback($results);
83 }
84}
storeLocal(string $key, mixed $complexData)
__construct(array $operations, \Closure $onCompletion)