wechatpay-apiv3/wechatpay-php

php 使用 swoole报错。

zhlhuang opened this issue · 15 comments

curl-native 已经确认开启了。

swoole

Swoole => enabled
Author => Swoole Team team@swoole.com
Version => 4.8.9
Built => Apr 19 2022 22:22:56
coroutine => enabled with boost asm context
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.0.2u 20 Dec 2019
curl-native => enabled
pcre => enabled
zlib => 1.2.7
mutex_timedlock => enabled
pthread_barrier => enabled
futex => 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 => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608

调用上传媒体素材报
WARNING ProcessPool::wait(): worker#3 abnormal exit, status=0, signal=11
....

GCC_VERSION: 4.8.5 20150623 (Red Hat 4.8.5-44)
OPENSSL_VERSION: OpenSSL 1.0.2u 20 Dec 2019
PHP_VERSION : 7.4.28

把你的上传代码贴一下

把你的上传代码贴一下
我今天尝试一下,将图片处理变小之后就可以成功。不知道是不是curl 处理有些限制的原因。也没有设置超时。

 $media = new MediaUtil($image_path);
        $resp = $this->weChatPayService->instance->chain('v3/merchant/media/upload')
            ->post([
                'body' => $media->getStream(),
                'headers' => [
                    'content-type' => $media->getContentType(),
                ]
            ]);

Guzzle 默认会在上传文件(文件大约1M)时,给添加 Expect: 100-continue 请求头,详细见这里,可以尝试在 post([])方法内,关闭或者按官方文档约定的最大允许文件字节值试试看,代码例如:

->chain('v3/merchant/media/upload')
->post([
    'body' => $media->getStream(),
    'headers' => [
        'Content-Type' => $media->getContentType(),
    ],
    'expect' => false,
 );

或者

->chain('v3/merchant/media/upload')
->post([
    'body' => $media->getStream(),
    'headers' => [
        'Content-Type' => $media->getContentType(),
    ],
    'expect' => 2*1024*1024+1,
 );

@TheNorthMemory 还是不行,我测试图片大小,大概是大于64K调用接口就会报错。不知道是不是我系统或者是swoole有些配置出错了。

建议看下 hyperf/hyperf#2055 ,直觉上你应该是用的hyperf的吧?

建议看下 hyperf/hyperf#2055 ,直觉上你应该是用的hyperf的吧?

我测出来确实超过64K就会出现错误,我看看是不是nginx配置上有问题。

你把你代码里的 content-type 改成 Content-Type , 以及增加 'expect' => false 试一试

你把你代码里的 content-type 改成 Content-Type , 以及增加 'expect' => false 试一试

试过了,还是不行。感觉是系统或者是swoole配置的问题。

请求发送出来了吗?还是本地出错了?

请求发送出来了吗?还是本地出错了?

我认为请求是没发出去的,异常也没抛。排查一天了,64K不知道是那个配置。同样的环境我换成了fpm没有问题。感觉是我swoole或者是操作系统的问题。

建议看下 hyperf/hyperf#2055 ,直觉上你应该是用的hyperf的吧?

我测出来确实超过64K就会出现错误,我看看是不是nginx配置上有问题。

php stream读取文件时一个块大小刚好就是64KB,直觉是你的环境curl版本与swoole的native-curl不配套所致,类似延展阅读可以看这里 swow/swow#65 (comment)

另外,你的环境openssl版本是1.0.2u,这个也是个潜在的问题点,curl在处理tls请求时,也用到了openssl,也可能不配套。

建议用docker拉齐 php7.4.28 openssl 1.1.1n curl7.82.0 再试试看。

升级了openssl还是不行。 curl 版本是 7.29.0 。不知道怎么排查是不是与swoole 的 native-curl 配套

建议给个完整样本代码(敏感信息可略去)。

建议给个完整样本代码(敏感信息可略去)。

@TheNorthMemory 我曲线救国进行排查,我用easyWechat 4.5.0 使用小程序上传素材的接口是正常的。但是这个sdk的就有问题,我现在可以肯定应该是是这个sdk的问题。 我使用的 guzzlehttp/guzzle 是 7.4.1

如果有新的反馈,可以随时再打开