swoole / swoole-src

🚀 Coroutine-based concurrency library for PHP
https://www.swoole.com
Apache License 2.0
18.62k stars 3.17k forks source link

调用阿里云OSS STS-token服务无法正常返回结果 #5706

Closed Torontototokyo closed 1 week ago

Torontototokyo commented 1 week ago

Please answer these questions before submitting your issue. Thanks!

  1. What did you do? If possible, provide a simple script for reproducing the error.

composer require alibabacloud/sts-20150401 composer require alibabacloud/darabonba-openapi alibabacloud/tea-utils alibabacloud/tea-console

StsService.php

<?php

namespace App\Index\Service;

use AlibabaCloud\SDK\Sts\V20150401\Models\AssumeRoleRequest;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;
use Darabonba\OpenApi\Models\Config;

class StsService
{

    public function init()
    {

    // 配置阿里云 STS
        $accessKeyId = env("Public_Session_AccessKey_ID"); // RAM 用户的 AccessKeyId
        $accessKeySecret = env("Public_Session_AccessKey_Secret"); // RAM 用户的 AccessKeySecret
        $endpoint = 'sts.aliyuncs.com'; // STS 服务地址

        $RoleArn = env('RoleArn');

        $RoleSessionName = 'public-session';

        $policy = json_encode([
            'Statement' => [
                [
                    'Effect' => 'Allow',
                    'Action' => [
                        'oss:PutObject',
                        'oss:GetObject',
                    ],
                    'Resource' => [
                        'acs:oss:*:*:forone-sites', // 允许访问的 Bucket
                        'acs:oss:*:*:forone-sites/*', // 允许访问的 Bucket 下的所有文件
                    ],
                ],
            ],
            'Version' => '1',
        ]);
        $client = self::createClient();
        $assumeRoleRequest = new AssumeRoleRequest([]);
        $runtime = new Utils\RuntimeOptions([
            'RoleArn'=>$RoleArn
        ]);
        try {
            $resp = $client->assumeRoleWithOptions($assumeRoleRequest, $runtime);

            var_dump($resp);
        }
        catch (\Throwable $error) {
            if (!($error instanceof TeaError)) {
                $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
            }
            // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
            // 错误 message
            var_dump($error->message);
            // 诊断地址
            var_dump($error->data["Recommend"]);
            Utils::assertAsString($error->message);
        }
    }

    public static function createClient(){
        $ALIBABA_CLOUD_ACCESS_KEY_ID = env('Public_Session_AccessKey_ID');
        $ALIBABA_CLOUD_ACCESS_KEY_SECRET = env('MTZ3n2eBDlIX0tYAepmsE9FtP7ecsa');
        // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例仅供参考。
        // 建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/311677.html。
        $config = new Config([
            // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
            "accessKeyId" => $ALIBABA_CLOUD_ACCESS_KEY_ID,
            // 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
            "accessKeySecret" => $ALIBABA_CLOUD_ACCESS_KEY_SECRET
        ]);
        // Endpoint 请参考 https://api.aliyun.com/product/Sts
        $config->endpoint = "sts.cn-shenzhen.aliyuncs.com";
        return new \AlibabaCloud\SDK\Sts\V20150401\Sts($config);
    }
}
  1. What did you expect to see? http请求正常返回
  2. What did you see instead?[2025-03-14 09:18:04 $66019.0] WARNING Server::check_worker_exit_status(): worker(pid=66025, id=5) abnormal exit, status=0, signal=11
  3. What version of Swoole are you using (php --ri swoole)?###php --ri swoole
swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 5.0.0
Built => Sep  9 2022 10:34:32
coroutine => enabled with boost asm context
kqueue => enabled
rwlock => enabled
openssl => OpenSSL 1.1.1o  3 May 2022
dtls => enabled
http2 => enabled
json => enabled
curl-native => 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
  1. What is your machine environment used (including the version of kernel & php & gcc)?
    
    php -v

PHP 8.0.30 (cli) (built: Dec 16 2024 20:48:34) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.30, Copyright (c) Zend Technologies with Yasd v0.3.9-alpha, Our Copyright, by codinghuang with Zend OPcache v8.0.30, Copyright (c), by Zend Technologies


sysctl kern.version

kern.version: Darwin Kernel Version 22.5.0: Thu Jun  8 22:22:19 PDT 2023; root:xnu-8796.121.3~7/RELEASE_ARM64_T8103
NathanFreeman commented 1 week ago

麻烦执行一下php -m 或者检查php和swoole用的是同一个版本的curl吗

Torontototokyo commented 1 week ago

麻烦执行一下php -m 或者检查php和swoole用的是同一个版本的curl吗

[PHP Modules] bcmath bz2 calendar Core ctype curl date dba dom exif FFI fileinfo filter ftp gd gettext gmp hash iconv intl json ldap libxml mbstring mysqli mysqlnd odbc openssl pcntl pcre PDO pdo_dblib pdo_mysql PDO_ODBC pdo_pgsql pdo_sqlite pgsql Phar phpdbg_webhelper posix pspell readline redis Reflection session shmop SimpleXML soap sockets sodium SPL sqlite3 standard swoole sysvmsg sysvsem sysvshm tidy tokenizer xml xmlreader xmlwriter xsl yasd Zend OPcache zip zlib

[Zend Modules] Yasd Zend OPcache

NathanFreeman commented 1 week ago

https://github.com/swoole/swoole-src/issues/5683 试试看是不是opcache的参数引发的问题

如果还不行,使用gdb或者valgrind调试一下 https://wiki.swoole.com/zh-cn/#/other/issue?id=%e5%85%b3%e4%ba%8e%e6%ae%b5%e9%94%99%e8%af%af%e6%a0%b8%e5%bf%83%e8%bd%ac%e5%82%a8

Torontototokyo commented 1 week ago

#5683 试试看是不是opcache的参数引发的问题

如果还不行,使用gdb或者valgrind调试一下 https://wiki.swoole.com/zh-cn/#/other/issue?id=%e5%85%b3%e4%ba%8e%e6%ae%b5%e9%94%99%e8%af%af%e6%a0%b8%e5%bf%83%e8%bd%ac%e5%82%a8

刚刚升级到5.1.x版本,正常了