我已經創建了一個電報機器人和我想能夠使當電報機器人接收特定使用exec命令在index.php執行在背景另一個PHP(worker.php)來自用戶的消息。 如果可能的話,我希望以比Heroku example更簡單的方式做到這一點。 worker.php代碼也應該能夠發送消息給電報聊天,因爲index.php正在執行。 然後我設置了這個例子來檢查參數傳遞(特別是聊天信息),但事實並非如此。這是代碼,有人可以幫忙嗎?目前並不真正在後臺運行,因爲/ dev/null &命令未在「exec」命令中設置。的Heroku,PHP,exec和電報機器人
在 「發件人」 的一面:
$update_j = json_encode($update);
$response = $client->sendMessage([
'chat_id' => $update->message->chat->id,
'text' => $update_j
]);
exec('php /app/worker.php?update=' . $update_j, $out, $ret_v);
的$ update_j輸出看起來是正確的:
{"update_id":XXXXXXXXX,"message":{"message_id":YYYY,"from":{"id":ZZZZZZZZ,"first_name":"Name"},"chat":{"id":ZZZZZZZZ,"first_name":"Name","type":"private"},"date":WWWWWWWWWWW,"text":"\/runjob","entities":[{"type":"bot_command","offset":0,"length":7}]}}
在worker.php側,代碼是這樣的:
<?php
require 'vendor/autoload.php';
require 'require.php';
try {
$foo = file_get_contents("php://input");
$out = json_decode($foo, true);
$update = $out->{'update'};
$response = $client->sendChatAction(['chat_id' => $update->message->chat->id, 'action' => 'typing']);
$response = $client->sendMessage([
'chat_id' => $update->message->chat->id,
'text' => "var_dump = " . var_dump($out)
]);
} catch (\Zelenin\Telegram\Bot\NotOkException $e) {}
$ ret_v的值爲1.我沒有收到任何包含var_dump($ out)值的消息。
有人可以幫助解決問題嗎? 謝謝。