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
支持Swoole的cURL handle #166
Conversation
There was a problem hiding this 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
就可以了,不需要兼容
<?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 |
@sy-records 那要考虑加入加入如下判断嘛? if ($curl_handle instanceof \Swoole\Curl\Handler) {
throw new RequestCore_Exception('Please set SWOOLE_HOOK_NATIVE_CURL');
} 不然会有如下奇怪的异常
|
我不是阿里的,这里是is_resource判断的问题,等兼容php8以后就可以了 #153 |
$ 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);
在阿里云 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')) { |
和 |
可以通过 @NeverRetrun Hyperf的等会我来提个pr进行支持 |
@sy-records 好的 那再好不过了。
|
fixed in v2.6.0 |
支持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