定时器里面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();
卡住了
看下 http://localhost:81 服务为什么会卡主不返回
建议设置一下Timeout参数,防止请求不响应的时候卡住····