From 65a3ad8628658f193d7b34c129060142030913d7 Mon Sep 17 00:00:00 2001 From: Lkeme <19500576+lkeme@users.noreply.github.com> Date: Sat, 4 Jan 2020 21:35:19 +0800 Subject: [PATCH] [fix] Curl --- composer.json | 2 +- composer.lock | 18 ++++++++---------- src/core/Curl.php | 26 +++++++++++++++++--------- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/composer.json b/composer.json index 84e1a49..81cf215 100644 --- a/composer.json +++ b/composer.json @@ -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": [ diff --git a/composer.lock b/composer.lock index ce7aa83..fccbe83 100644 --- a/composer.lock +++ b/composer.lock @@ -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": { diff --git a/src/core/Curl.php b/src/core/Curl.php index 74bf276..f96ab8e 100644 --- a/src/core/Curl.php +++ b/src/core/Curl.php @@ -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']