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

Request.php 309行 echo $package,"\n"; #31

Closed
21307369 opened this issue Jun 8, 2024 · 2 comments
Closed

Request.php 309行 echo $package,"\n"; #31

21307369 opened this issue Jun 8, 2024 · 2 comments

Comments

@21307369
Copy link

21307369 commented Jun 8, 2024

<?php

namespace app\common;

use Monolog\Logger;
use Workerman\Http\Client;

class httpClient
{
    private static Client $client;

    public static function init(): void
    {
        if (!isset(self::$client)) {
            $options = [
//                'max_conn_per_addr' => 128,
//                'keepalive_timeout' => 10,
//                'connect_timeout' => 10,
//                'timeout' => 10,
            ];
            self::$client = new Client($options);
        }
    }

    /**
     * @param string $backUrl
     * @param array $data 
     * @return false
     * @throws \Throwable
     */
    public static function RequestPost(string $backUrl, array $data): bool
    {
        self::init();
        self::$client->post($backUrl, $data,
            function ($response) use ($data, $backUrl, $log) {
                $body = $response->getBody()->getContents();
                if ($response->getStatusCode() === 200 && $body === 'success') {
                    //等待异步通知
                   }
            },
            function ($exception) use ($data, $backUrl) { //异常处理
               
            }
        );
        return true;
    }
}

很奇怪我有2个地方使用RequestPost 我有2个应用 一个APP,一个admin APP请求正常,admin请求会在控制台输出
POST / HTTP/1.1
Host: xxxxxxx
User-Agent: workerman/http-client
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 127

@walkor
Copy link
Owner

walkor commented Jun 8, 2024 via email

@21307369
Copy link
Author

21307369 commented Jun 8, 2024

self::$client->post 外部包一个
try {
} 就不输出日志了.也是奇怪

@21307369 21307369 closed this as completed Jun 8, 2024
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

No branches or pull requests

2 participants