国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

??
1. ????
2. ThinkPHP6 ??? ??
rrreee
? PHP ????? ThinkPHP ??? ?? ??? ThinkPHP6? ???? ??? ??????

??? ?? ??? ThinkPHP6? ???? ??? ??????

Jun 12, 2023 am 09:57 AM
thinkphp ???? ?? ??

???? ??? ??? ?? ?? ???? ?? ??? ? ??????? ?? ??? ?????. ?? ?? ?? ? ?? ????? ?? ??? ?? ??? ???? ?? ?? ? ????? ThinkPHP6 ?????? ???? ??? ?? ??? ???? ??? ?????.

1. ????

??? ?? ???? ??? ??? ????? ???? ??? ? ??? ???? ?? ?????. ????? ??? ???? ???? ??????? ?????. ??? ???? ?? ??? ???? ??? ??? ?? ? ?????? ???? ???? ???? ????? ? ??? ???.

? ???????? ??? ???? ????? ???? ??? ??? ? ? ???? ? ??? ? ? ????. ??? ???? ???? ??????? ??? ??? ??? ??? ??? ???? ??? ? ????.

2. ThinkPHP6 ??? ??

?????? ?? ???? ??? ?? ?????. ???, ??? ????? ??? ?? ??? ??? ??? ? ? ?? ?? ???? ??? ??? ????. ?? ?? ThinkPHP6??? ??? ?? ??? ???? ??? ? ?? ??????? ?? ??? ??? ??? ??? ???.

????? ????? ??? ???? ? ??? PsrLogLoggerInterface ?????? ???? ?? ?????. PsrLogLoggerInterface 接口來實現(xiàn)。

// Controller或Model中
use PsrLogLoggerInterface;

public function index(LoggerInterface $logger){
    $logger->info('hello world');
}

簡單的使用方式。使用異步日志記錄,定義一個異步日志記錄器:

use MonologLogger;
use MonologHandlerStreamHandler;

$logger=new Logger("AsyncLogger");
$logger->pushHandler(new StreamHandler('runtime/log/async.log'), Logger::INFO);

日志記錄器定義好后,使用隊列發(fā)送日志記錄信息,這里我們選擇使用 RabbitMQ 當做隊列服務(wù)。

// Message類
namespace appcommon;

class Message
{
    /**
     * 記錄日志
     * @param $level
     * @param $message
     * @param array $context
     * @return bool
     */
    public static function log($level,$message,array $context=[]){
        $data=[
            'level'=>$level,
            'message'=>$message,
            'context'=>$context,
            'channel'=>'AsyncLogger',
            'datetime'=>date('Y-m-d H:i:s'),
            'host'=>$_SERVER['SERVER_ADDR'] ?? '',
            'uri'=>$_SERVER['REQUEST_URI'] ?? '',
        ];

        $producer=Queue::getConnection('AsyncLogger',true);
        $producer->setExchangeOptions(['name'=>'async_logs','type'=>'topic','durable'=>true])->declareExchange();

        try{
            $producer->publish(json_encode($data),[
                'routing_key' =>'log',
                'exchange' =>'async_logs',
            ]);
            return true;
        }catch (Exception $e){
            return false;
        }
    }
}

其中,我們使用 appcommonQueue 類來提供 rabbitmq 的連接實例;data中除了記錄日志的信息外,還包含一些環(huán)境信息,比如時間、IP地址、請求的uri地址等。

隊列處理程序:

// Consumer類
use BunnyMessage;
use PsrLogLoggerInterface;

class Consumer
{
    /**
     * @param Message $message
     * @param LoggerInterface $logger
     */
    public function process(Message $message,LoggerInterface $logger){
        $body=$message->content;
        $data= json_decode($body,true);
        $channel=$data['channel'] ?? 'default_logger';

        $logger->notice($data['message'], $data);
    }
}

當然,我們還需要一個輔助處理日志的類。

// Queue類
namespace appcommon;

use BunnyAsyncClient;
use BunnyChannel;
use BunnyMessage;
use BunnyProtocolMethodBasicConsumeOkFrame;
use BunnyProtocolMethodChannelCloseFrame;
use BunnyProtocolMethodChannelCloseOkFrame;
use BunnyProtocolMethodConnectionCloseFrame;
use BunnyProtocolMethodConnectionCloseOkFrame;
use BunnyProtocolMethodConnectionStartFrame;
use BunnyClientStateEnum;
use BunnyMessage as BunnyMessage;

class Queue
{
    /**
     * @param string $queueName
     * @return Client|null
     */
    public static function getConnection(string $routingKey, bool $persistent=false):?Client
    {
        $config=config('rabbitmq.async_log');
        $client=new Client([
            'host' => $config['host'],
            'port' => $config['port'],
            'user' => $config['user'],
            'password' => $config['password'],
            'vhost' => $config['vhost'],//注意此處改為需要的 VHOST
            'concurrency' => 2,
        ]);

        try{
            $client->connect();
            $client->channel()
                ->then(function (Channel $channel) use($client,$routingKey,$persistent){
                    $channel->exchangeDeclare('async_logs','topic',true,true);
                    $channel->queueDeclare($routingKey, $passive=false,$durable=true,$exclusive=false,$autoDelete=false,$nowait=false);
                    $channel->queueBind($routingKey, 'async_logs', $routingKey);

                    $channel->consume(
                        function ($msg, Channel $channel, BunnyMessage $message) use($client,$routingKey){
                            $className=config('rabbitmq.async_log.consumer');
                            $consumer=new $className($client,$routingKey);
                            $consumer->process($message,app('log.async_logger'));
                            $channel->ack($msg);//處理消息
                        },
                        $routingKey,//隊列Name
                        '',//消費Tag
                        false,//no_local
                        false,//no_ack
                        false,//exclusive
                        $persistent ? ['delivery_mode'=>2] : []
                    );
                });
        }catch (Exception $e){
            return null;
        }finally{
            return $client;
        }
    }
}

上面這段代碼中定義了隊列連接的 host、port 等,通過 $client->channel() 創(chuàng)建了一個 channel 對象,通過 $channel->exchangeDeclare()$channel->queueDeclare() 創(chuàng)建了 exchange 和 queue,并將它們進行了綁定。最后,使用 $channel->consume()rrreee

???? ????. ??? ??? ???? ??? ?? ??:

rrreee

??? ??? ? ???? ???? ?? ??? ????. ???? RabbitMQ? ??? ???? ????? ?????.

rrreee

? ? appcommonQueue ???? ???? ?? ?? ?? ??? data?? ?? ? IP? ?? ?? ?? ??? ???? ????. ??, ??? URI ?? ?
  1. ? ???:
  2. rrreee
  3. ?? ?? ??? ???? ???? ?????.
  4. rrreee
  5. ? ??? ? ??? ???, ?? ?? ???? ???, $client->channel()? ?? ?? ??? ????, ? ?? ?? ??? ?????. >$channel->exchangeDeclare () ? $channel->queueDeclare()? exchange? queue? ???? ??????. ????? $channel->consume()? ???? ???? ???? ?????? ???? ?? ???? ??? ?? ???? ????.
3. ??

? ???? ??? ? ?? ??????? ?? ??? ??? ??? ??? ThinkPHP6 ?????? ???? ??? ?? ??? ???? ??? ?????. ????? ?? ??? ??? ????. ?????????? ??? ?? ?? ??????? ??? ??? RabbitMQ ?? ??????? ??? ?? ???????? ??????? ?? ?? ??? ?? ??? ????? ???? ???. ???? ??. ??? ??? ?? ? ??????? ?? ???? ????? ???? ? ??? ???? ???? ???? ???? ? ????. ??

? ??? ??? ?? ??? ThinkPHP6? ???? ??? ??????? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? ????? ??
? ?? ??? ????? ???? ??? ??????, ???? ?????? ????. ? ???? ?? ???? ?? ??? ?? ????. ???? ??? ???? ???? ??? ?? admin@php.cn?? ?????.

? AI ??

Undresser.AI Undress

Undresser.AI Undress

???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover

AI Clothes Remover

???? ?? ???? ??? AI ?????.

Video Face Swap

Video Face Swap

??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

???

??? ??

???++7.3.1

???++7.3.1

???? ?? ?? ?? ???

SublimeText3 ??? ??

SublimeText3 ??? ??

??? ??, ???? ?? ????.

???? 13.0.1 ???

???? 13.0.1 ???

??? PHP ?? ?? ??

???? CS6

???? CS6

??? ? ?? ??

SublimeText3 Mac ??

SublimeText3 Mac ??

? ??? ?? ?? ?????(SublimeText3)

???

??? ??

??? ????
1601
29
PHP ????
1502
276
???
thinkphp ????? ???? ?? thinkphp ????? ???? ?? Apr 09, 2024 pm 05:33 PM

ThinkPHP ????? ????? ??? ?????: Composer? ????, ???? ????? ???? php bin/console? ????, ?? ???? ??? http://localhost:8000? ?????.

thinkphp?? ?? ??? ????. thinkphp?? ?? ??? ????. Apr 09, 2024 pm 06:09 PM

ThinkPHP?? ??? PHP ????? ??? ?? ??? ????. ??? ???? 3.2, 5.0, 5.1, 6.0? ????, ??? ??? ??? ???? ??? ??? ???? ? ?????. ?? ?? ??? ThinkPHP 6.0.16???. ??? ??? ? PHP ??, ?? ?? ?? ? ???? ??? ??????. ??? ??? ??? ???? ?? ?? ??? ???? ?? ????.

thinkphp? ???? ?? thinkphp? ???? ?? Apr 09, 2024 pm 05:39 PM

ThinkPHP Framework? ???? ???? ??: ThinkPHP Framework? ?? ????? ?????? ??? ???. ThinkPHP ?? ????? ???? ?? ???(?? ??)? ????. ?????? ?? ????? ?????. ? ??? ?????. ThinkPHP ??????? ??????. ThinkPHP ?????? URL? ???? ?????.

laravel? thinkphp ? ?? ?? ? ???? laravel? thinkphp ? ?? ?? ? ???? Apr 09, 2024 pm 03:18 PM

Laravel? ThinkPHP ?????? ?? ??: ThinkPHP? ????? ??? ? ??? ??? ?? Laravel?? ??? ????. Laravel? ? ????? ??? ??????? ?? ThinkPHP? ? ??? ? ????.

thinkphp? ???? ?? thinkphp? ???? ?? Apr 09, 2024 pm 05:42 PM

ThinkPHP ?? ??: PHP, Composer ? MySQL ??? ?????. Composer? ???? ????? ????. ThinkPHP ?????? ???? ?????. ?????? ??? ?????. ?????? ??? ?????. ??????? ???? http://localhost:8000? ?????.

thinkphp ??? ????? thinkphp ??? ????? Apr 09, 2024 pm 05:24 PM

ThinkPHP? ?? ????, ?? ???, ?? ?? ? ?????? ???? ?? ??? ?? ??? PHP ????????. ?? ?? ???? ??? ?? 10,000? ??? ??? ??? ? ??? JD.com, Ctrip? ?? ??? ? ??? ? ?????? ????? ?? ?? ?????? ?? ?????.

Java ??? ?? ????? ??? ?? ?????? ???? ??? ?????? Java ??? ?? ????? ??? ?? ?????? ???? ??? ?????? May 04, 2024 am 11:33 AM

Java ????? ?? ??? ?? ?????? ??? ? ?? ??? ???? ???. ??: ?? ?? ?? ???? ???? ??? ?? ???: ??? ?? ?? ?? ???: ??? ???? ?? ?? ?? ?? ???? ??: ?? ?? ? ?? ?? ??

thinkphp ????? ???? ?? thinkphp ????? ???? ?? Apr 09, 2024 pm 05:36 PM

ThinkPHP ????? ????? ??? ???? ???. 1. ?? ????? ????. 2. ??????? ?????. 4. ?????? ??? ???? ??? ?????. 7. ????? ?????. ?? ???? ??? ?? ??, ???? ?? ??? ? ???? ??? ?????.

See all articles