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
22
declare(strict_types=1);
23
24
namespace
pocketmine\scheduler
;
25
26
use
pocketmine\utils\Internet
;
27
use
pocketmine\utils\InternetException
;
28
use
pocketmine\utils\InternetRequestResult
;
29
use
function
igbinary_serialize;
30
use
function
igbinary_unserialize;
31
37
class
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
}
pocketmine\scheduler\AsyncTask
Definition
AsyncTask.php:61
pocketmine\scheduler\AsyncTask\storeLocal
storeLocal(string $key, mixed $complexData)
Definition
AsyncTask.php:214
pocketmine\scheduler\BulkCurlTask
Definition
BulkCurlTask.php:37
pocketmine\scheduler\BulkCurlTask\onRun
onRun()
Definition
BulkCurlTask.php:57
pocketmine\scheduler\BulkCurlTask\onCompletion
onCompletion()
Definition
BulkCurlTask.php:74
pocketmine\scheduler\BulkCurlTask\__construct
__construct(array $operations, \Closure $onCompletion)
Definition
BulkCurlTask.php:52
pocketmine\utils\InternetException
Definition
InternetException.php:26
pocketmine\utils\Internet
Definition
Internet.php:66
pocketmine\utils\InternetRequestResult
Definition
InternetRequestResult.php:26
pocketmine\scheduler
Definition
AsyncPool.php:24
src
scheduler
BulkCurlTask.php
Generated by
1.12.0