我希望得到回复200,然后继续完成该任务。
例如,在下面的代码中,我在echo json_encode($data, JSON_PRETTY_PRINT)
之后在Laravel 5.2中写了一条短信和电子邮件
这是最佳做法吗?
以下代码存在哪些问题和缺陷?
ob_end_clean();
header("Connection: close\r\n");
header("Content-Encoding: none\r\n");
header("Content-Type: application/json\r\n");
header('HTTP/1.1 201 Created', true, 201);
ignore_user_abort(true); // optional
ob_start();
$data = [
"data" => $register['cell_phone']
];
echo json_encode($data, JSON_PRETTY_PRINT);
$size = ob_get_length();
header("Content-Length: $size");
ob_end_flush(); // Strange behaviour, will not work
flush(); // Unless both are called !
if (session_id()) session_write_close(); // Added a line suggested in the comment
$this->sms->send_by($register['cell_phone'],trans('customer.your_activation_code').Crypt::decrypt($register['activation_code']));
if($request->get('email') !==null)
{
$this->email->send_by($request->get('email'),Crypt::decrypt($register['activation_code']));
}
sleep(20);