Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持Swoole的cURL handle #166

Closed
wants to merge 1 commit into from
Closed

Conversation

coleflowers
Copy link

支持Swoole的cURL handle,运行测试环境:

$php --version
PHP 7.4.14 (cli) (built: Mar 23 2021 11:21:02) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

$php --ri swoole

swoole

Swoole => enabled
Author => Swoole Team team@swoole.com
Version => 4.6.2
Built => Mar 23 2021 16:33:39
coroutine => enabled with boost asm context
kqueue => enabled
rwlock => enabled
openssl => OpenSSL 1.1.1j 16 Feb 2021
dtls => enabled
http2 => enabled
pcre => enabled
zlib => 1.2.11
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => Off => Off
swoole.unixsock_buffer_size => 262144 => 262144

Copy link

@sy-records sy-records left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

高版本直接使用SWOOLE_HOOK_NATIVE_CURL就可以了,不需要兼容

@coleflowers
Copy link
Author

<?php

class B {

}
$curl_handle = new B();
if (class_exists('\Swoole\Curl\Handler')) {
	echo 'yes' . PHP_EOL;
} else {
	echo 'no' . PHP_EOL;
}
if (is_resource($curl_handle) || ($curl_handle instanceof \Swoole\Curl\Handler)) {
	echo 'yes' . PHP_EOL;
} else {
	echo 'no' . PHP_EOL;
}
$curl_handle = curl_init();
if (is_resource($curl_handle) || ($curl_handle instanceof \Swoole\Curl\Handler)) {
	echo 'yes' . PHP_EOL;
} else {
	echo 'no' . PHP_EOL;
}
$php -m | grep swoole
$php test.php 
no
no
yes

@coleflowers
Copy link
Author

@sy-records 那要考虑加入加入如下判断嘛?

if ($curl_handle instanceof \Swoole\Curl\Handler) {
    throw new RequestCore_Exception('Please set SWOOLE_HOOK_NATIVE_CURL');
}

不然会有如下奇怪的异常

OSS\Core\OssException: :  RequestId: 

@sy-records
Copy link

我不是阿里的,这里是is_resource判断的问题,等兼容php8以后就可以了 #153

@NeverRetrun
Copy link

@sy-records

$ php --ri swoole

swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.7.0
Built => Aug 25 2021 14:35:14
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.1.1k  25 Mar 2021
dtls => enabled
http2 => enabled
json => enabled
curl-native => enabled
pcre => enabled
zlib => 1.2.11
brotli => E16777225/D16777225
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608
在hyperf中设置了swoole hook flags

! defined('SWOOLE_HOOK_FLAGS') && define('SWOOLE_HOOK_FLAGS', SWOOLE_HOOK_ALL | SWOOLE_HOOK_NATIVE_CURL);

在阿里云 vendor/aliyuncs/oss-sdk-php/src/OSS/Http/RequestCore.php line 793行出现这样的情况

    public function process_response($curl_handle = null, $response = null)
    {
        // Accept a custom one if it's passed.
        if ($curl_handle && $response) {
            $this->response = $response;
        }

       这里获取的$curl_handle类型是 Swoole\Coroutine\Curl\Handle
       is_resource($curl_handle) === false
       导致直接跳过了判断直接抛出异常。 

        if (is_resource($curl_handle) || (is_object($curl_handle) && get_class($curl_handle) === 'CurlHandle')) {

@sy-records
Copy link

is_resource没关系,阿里云限制太死了,正常用is_object判断就好了,还加了一个get_class($curl_handle) === 'CurlHandle'),所以导致直接异常了

@sy-records
Copy link

可以通过composer require sy-records/swoole-hook-addon来兼容OSS。

@NeverRetrun Hyperf的等会我来提个pr进行支持

@NeverRetrun
Copy link

@sy-records 好的 那再好不过了。

hyperf/flysystem-oss hyperf这个包依然是基于阿里云sdk的 目前是处于不可用的情况

@huiguangjun
Copy link
Contributor

fixed in v2.6.0

@huiguangjun huiguangjun closed this Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants