我刚刚拿起 AmPHP,我正试图从我的 AmPHP http 服务器获取帖子正文,但是,它会一直持续下去(只是永远不会向我的客户发送回复)。
这是我目前正在使用的代码:
$resp = \Amp\Promise\wait($request->getBody()->buffer());
我已经测试了另一段不会永远运行的代码,但是当我使用那段代码时,我无法将我的身体置于以下函数之外onResolve
:
$resp = $request->getBody()->buffer()->onResolve(function($error, $value) {
return $value;
});
return $resp; // returns null
我也试过最后一点,但也只是返回null
:
return yield $request->getBody()->buffer();
编辑:做了更多的摆弄,这是我当前的(仍然没有功能的)代码(虽然为了简单起见,很多已经被剥离了):
// Main loop
Loop::run(function() {
$webhook = new Webhook();
$resp = $webhook->execute($request);
print_r($resp); // null
});
// Webhook
class Webhook {
public function execute(\Amp\Http\Server\Request $request) {
$postbody = yield $request->getBody()->buffer();
return ['success' => true, 'message' => 'Webhook executed successfully', 'data' => $postbody];
}
}