我正在使用来自的示例 https://github.com/SparkPost/php-sparkpost#send-an-email-using-the-transmissions-endpoint
这里有asynch承诺: https://github.com/SparkPost/php-sparkpost#then-asynchronous
使用Composer正确安装了所有内容。如果我使用$ response = $ promise-> wait();发送电子邮件但不是$ promise->然后(function(){},function(){})
我从命令行运行php脚本,asynch选项设置为true
/// this works:
try {
$response = $promise->wait();
echo $response->getStatusCode()."\n";
print_r($response->getBody())."\n";
} catch (\Exception $e) {
echo $e->getCode()."\n";
echo $e->getMessage()."\n";
}
// but this doesn't
$promise->then(
// Success callback
function ($response) {
echo $response->getStatusCode()."\n";
print_r($response->getBody())."\n";
},
// Failure callback
function (Exception $e) {
echo $e->getCode()."\n";
echo $e->getMessage()."\n";
}
);
答案 0 :(得分:1)
SparkPost文档中存在错误(或只是一个错误的假设)。
无论如何,你必须以某种方式致电->wait()
。所以,只需在第二个脚本的末尾添加$promise->wait();
,就可以了。
以某种方式""我的意思是你可以使用all()
, some()
and other functions将承诺组合在一起。