定时器里面curl卡住了

phpfuns

问题描述

定时器里面curl卡住了

程序代码

$worker            = new Worker('http://0.0.0.0:2346');
$worker->onMessage = function (TcpConnection $connection, $data) {
    $order = $data['post']['order'];
    Timer::add(1, function () use ($order, $connection) {
    echo "{$order}\n";
    $postData = [
    'order' => 1,
    ];
    $url = 'http://localhost:81/callback/index';
    $ch  = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, 2);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $response = curl_exec($ch);
    if (curl_errno($ch)) {
    $error_msg = curl_error($ch);
    echo "cURL Error: " . curl_errno($ch);
    }
    curl_close($ch);

    $connection->close('SUCCESS');
    }, [], false);
};
Worker::runAll();

报错信息

卡住了
204 2 0
2个回答

six

看下 http://localhost:81 服务为什么会卡主不返回

  • 暂无评论
释永战

建议设置一下Timeout参数,防止请求不响应的时候卡住····

  • 暂无评论
🔝