[fix] Curl

This commit is contained in:
Lkeme 2020-01-04 21:35:19 +08:00
parent 2d3362196c
commit 65a3ad8628
3 changed files with 26 additions and 20 deletions

View File

@ -15,7 +15,7 @@
"clue/socket-raw": "^1.4.1",
"vlucas/phpdotenv": "^4.1",
"amphp/amp": "^2.4",
"lkeme/curl-future": "dev-master"
"lkeme/curl-future": "^0.0.1"
},
"license": "MIT",
"authors": [

18
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "6e83be077b5af9863dab5c4affd54c0b",
"content-hash": "94b2a09fe75ecf7401a6694e164b252c",
"packages": [
{
"name": "amphp/amp",
@ -246,16 +246,16 @@
},
{
"name": "lkeme/curl-future",
"version": "dev-master",
"version": "v0.0.1",
"source": {
"type": "git",
"url": "https://github.com/lkeme/CurlFuture.git",
"reference": "084f1004ba722b72755c7519932117d7fb72c214"
"reference": "f588d890eee745d8ecd3ee1135ac6de899381e15"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/lkeme/CurlFuture/zipball/084f1004ba722b72755c7519932117d7fb72c214",
"reference": "084f1004ba722b72755c7519932117d7fb72c214",
"url": "https://api.github.com/repos/lkeme/CurlFuture/zipball/f588d890eee745d8ecd3ee1135ac6de899381e15",
"reference": "f588d890eee745d8ecd3ee1135ac6de899381e15",
"shasum": "",
"mirrors": [
{
@ -280,8 +280,8 @@
"email": "263068280@qq.com"
}
],
"description": "Parallel CURL Requests with PHP",
"time": "2020-01-03T16:39:17+00:00"
"description": "Parallel CURL Requests with PHP --Fork",
"time": "2020-01-04T13:16:47+00:00"
},
{
"name": "monolog/monolog",
@ -613,9 +613,7 @@
"packages-dev": [],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
"lkeme/curl-future": 20
},
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": {

View File

@ -36,22 +36,30 @@ class Curl
$new_tasks = [];
$results = [];
$url = self::http2https($url);
$curl_options = [
CURLOPT_HEADER => 0,
CURLOPT_ENCODING => 'gzip',
CURLOPT_IPRESOLVE => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_TIMEOUT => $timeout,
CURLOPT_CONNECTTIMEOUT => $timeout,
];
if (($cookie = getenv('COOKIE')) != "") {
$curl_options[CURLOPT_COOKIE] = $cookie;
}
if (getenv('USE_PROXY') == 'true') {
$curl_options[CURLOPT_PROXY] = getenv('PROXY_IP');
$curl_options[CURLOPT_PROXYPORT] = getenv('PROXY_PORT');
}
foreach ($tasks as $task) {
$payload = $task['payload'];
$header = is_null($headers) ? self::getHeaders(self::$headers) : self::getHeaders($headers);
$options = [
'header' => $header,
'timeout' => $timeout,
'post_data' => is_array($payload) ? http_build_query($payload) : $payload
];
// $options['proxy_url'] = "127.0.0.1:8888";
if (getenv('USE_PROXY') == 'true') {
$options['proxy_url'] = "http://" . getenv('PROXY_IP') . ":" . getenv('PROXY_PORT');
}
if (($cookie = getenv('COOKIE')) != "") {
$options['header']['Cookie'] = $cookie;
}
$new_task = new HttpFuture($url, $options);
$new_task = new HttpFuture($url, $options, $curl_options);
array_push($new_tasks, [
'task' => $new_task,
'source' => $task['source']