首页 文章

Messenger bot回答速度问题

提问于
浏览
0

我不知道我是否只有这个问题,但我的messenger机器人存在严重问题 . 它是直接在php中构建的:

$accessToken =   "EAxxxxxxxxxxxqgBAKWAgizvoHnQLZBR7ZxxxxxxxxxxxxxxxxxxxxxxxxxxxxxptYSymSdocFFCp1ink3EHRVMrCSxxxxxxxxxxxxxxxxxxxxwMZApStyA8GbqAxxxxxxxxxxxxxxxxxxxxxxxxxxx9R6QttFVyNS4ZBurwZDZD";

$input = json_decode(file_get_contents('php://input'), true);
$senderId = $input['entry'][0]['messaging'][0]['sender']['id'];
$messageText = $input['entry'][0]['messaging'][0]['message']['text'];
$response = null;
//set Message
if($messageText == "hi") {
    $answer = "Hello";
}
//send message to facebook bot
$response = [
    'recipient' => [ 'id' => $senderId ],
    'message' => [ 'text' => $answer ]
];
$ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$accessToken);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($response));
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
if(!empty($input)){
$result = curl_exec($ch);
}
curl_close($ch);

但回复需要3-5秒 . 服务器在澳大利亚 . 但是当我尝试使用nodeJS的heroku Cloud 平台时,一切顺利,即时响应 . 你有什么想法或建议为什么会这样吗? nodeJS在这一点上是否更快,我应该考虑用这种语言制作机器人,或者它可能是其他东西?

1 回答

  • 0

    很难直接回答您的问题,因为我们无法重现您的服务器环境 . 我并不认为物理服务器位置或编程语言会像几秒钟那样造成如此大的延迟 . 我建议你尝试的一件事是从Heroku服务器向你在澳大利亚的服务器发送ping命令之类的请求 . 然后,至少你可以将问题分解为编程/软件问题或网络问题 .

相关问题