国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

workerman作為http服務(wù)接收大并發(fā)請(qǐng)求,nginx返回502

phpfuns

問(wèn)題描述

我用workerman做了一個(gè)http服務(wù),作用是作為定時(shí)器來(lái)通知第三方服務(wù)器,然后量大了以后,nginx日志里發(fā)現(xiàn)了,這種錯(cuò)誤:
2024/06/16 16:52:28 [error] 28425#0: *314 recv() failed (104: Connection reset by peer) while reading response header from upstream
頁(yè)面等待一段時(shí)間返回的是nginx502錯(cuò)誤。

程序代碼

這是tp框架的代碼,下單以后,給workerman發(fā)http請(qǐng)求。

    $postData = [
        'id' => $event,
    ];
    $url = 'http://localhost:2346';
    $ch  = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $response = curl_exec($ch);
    if (curl_errno($ch)) {
    $error_msg = curl_error($ch);
    trace($error_msg, 'error');
    }
    curl_close($ch);

這是workman代碼,接到請(qǐng)求以后,定時(shí)發(fā)通知

$worker            = new Worker('http://0.0.0.0:2346');
$worker->onMessage = function (TcpConnection $connection, Request $request) use ($db) {
    $post = $request->post();
    $id   = $post['id'];
    $connection->close();
    Timer::add(15, function () use ($connection, $id, $db) {
        echo "#{$connection->id} Order {$id}\n";
        $MerchantOrder = $db::table('merchant_order')->find($id);
        $postData      = [
            'order_id' => $MerchantOrder['order_id'],
            'amount'   => $MerchantOrder['amount'],
            'status'   => $MerchantOrder['status'],
            'notes'    => $MerchantOrder['notes'],
        ];
        $url = $MerchantOrder['callback_url'];
        $ch  = curl_init($url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $response = curl_exec($ch);
        if (curl_errno($ch)) {
            $error_msg = curl_error($ch);
            trace($error_msg, 'error');
        }
        curl_close($ch);
    }, [], false);
    Timer::add(30, function () use ($connection, $id, $db) {
        echo "#{$connection->id} Order {$id}\n";
        $MerchantOrder = $db::table('merchant_order')->find($id);
        $postData      = [
            'order_id' => $MerchantOrder['order_id'],
            'amount'   => $MerchantOrder['amount'],
            'status'   => $MerchantOrder['status'],
            'notes'    => $MerchantOrder['notes'],
        ];
        $url = $MerchantOrder['callback_url'];
        $ch  = curl_init($url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $response = curl_exec($ch);
        if (curl_errno($ch)) {
            $error_msg = curl_error($ch);
            trace($error_msg, 'error');
        }
        curl_close($ch);
    }, [], false);
    Timer::add(60, function () use ($connection, $id, $db) {
        echo "#{$connection->id} Order {$id}\n";
        $MerchantOrder = $db::table('merchant_order')->find($id);
        $postData      = [
            'order_id' => $MerchantOrder['order_id'],
            'amount'   => $MerchantOrder['amount'],
            'status'   => $MerchantOrder['status'],
            'notes'    => $MerchantOrder['notes'],
        ];
        $url = $MerchantOrder['callback_url'];
        $ch  = curl_init($url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $response = curl_exec($ch);
        if (curl_errno($ch)) {
            $error_msg = curl_error($ch);
            trace($error_msg, 'error');
        }
        curl_close($ch);
    }, [], false);
    Timer::add(180, function () use ($connection, $id, $db) {
        echo "#{$connection->id} Order {$id}\n";
        $MerchantOrder = $db::table('merchant_order')->find($id);
        $postData      = [
            'order_id' => $MerchantOrder['order_id'],
            'amount'   => $MerchantOrder['amount'],
            'status'   => $MerchantOrder['status'],
            'notes'    => $MerchantOrder['notes'],
        ];
        $url = $MerchantOrder['callback_url'];
        $ch  = curl_init($url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $response = curl_exec($ch);
        if (curl_errno($ch)) {
            $error_msg = curl_error($ch);
            trace($error_msg, 'error');
        }
        curl_close($ch);
    }, [], false);
    Timer::add(300, function () use ($connection, $id, $db) {
        echo "#{$connection->id} Order {$id}\n";
        $MerchantOrder = $db::table('merchant_order')->find($id);
        $postData      = [
            'order_id' => $MerchantOrder['order_id'],
            'amount'   => $MerchantOrder['amount'],
            'status'   => $MerchantOrder['status'],
            'notes'    => $MerchantOrder['notes'],
        ];
        $url = $MerchantOrder['callback_url'];
        $ch  = curl_init($url);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $response = curl_exec($ch);
        if (curl_errno($ch)) {
            $error_msg = curl_error($ch);
            trace($error_msg, 'error');
        }
        curl_close($ch);
    }, [], false);
};
Worker::runAll();

截圖報(bào)錯(cuò)信息里報(bào)錯(cuò)文件相關(guān)代碼

2024/06/16 16:52:28 [error] 28425#0: *314 recv() failed (104: Connection reset by peer) while reading response header from upstream

操作系統(tǒng)及workerman/webman等框架組件具體版本

導(dǎo)致以上問(wèn)題以后,我重啟一下workerman,又可以正常運(yùn)行,但是一段時(shí)間以后,必定還會(huì)出現(xiàn)這種問(wèn)題,所以我按照官網(wǎng)說(shuō)的先安裝了event擴(kuò)展,我現(xiàn)在就是觀察狀態(tài)中。
請(qǐng)問(wèn),我該如何優(yōu)化。
通過(guò)netstat查看端口進(jìn)程情況,發(fā)現(xiàn)有很多2346的。
那么現(xiàn)在,我不知道是哪一塊出了問(wèn)題,我該如何面對(duì)這一切。
我該不該上:workerman-http或者wokerman-mysql

986 2 0
2個(gè)回答

efnic

訂單按指定的間隔時(shí)間,通知回調(diào)方;這個(gè)用隊(duì)列來(lái)解決即可。

  • phpfuns 2024-06-18

    我去看了rabbitMQ了,目前我掌握不了,時(shí)間太緊了。謝謝。

TM

是不是超時(shí)沒(méi)處理斷連了

  • phpfuns 2024-06-18

    好像是的,我直接給curl加了個(gè)2秒超時(shí),就沒(méi)問(wèn)題了。謝謝。

年代過(guò)于久遠(yuǎn),無(wú)法發(fā)表回答
??