我有一家在线商店,我使用在线会计软件手动发布订单。在线会计软件有一个非常大的api,我想在客户下订单时自动发送订单。
一旦订单完成,客户就会进入成功页面,即 successpage.php
在此页面中,我有以下内容:
$sendOrder = file_get_contents("https://myonlinestore.com/sendorder.php?order=1234");
在 sendorder.php 上,我收到$_GET参数“order”,即订单号,我处理几个 SQL 请求以从数据库中检索订单数据。
获得所有这些数据后,我会启动一个 CURL 帖子,以使用会计系统的 API 发送数据。
这是我的代码的简化版本,其中包含基本部分:
$orderNum = htmlspecialchars($_GET["order"]) // SENT OVER FILE_GET_CONTENTS
// bOf process SQL here and get order info stored in various variables
// EXECUTE SQL HERE
// eOf process SQL here and get order info stored in various variables
$invoice = array(
'customer_id' => $custaccount,
'estimate_number' => $orderRef,
'reference_number' => $orderNum
// MANY OTHER VARIABLES ENTERED HERE, BUT LEFT OUT TO KEEP THINGS SHORT
);
$jsonInvoice = json_encode($invoice);
$url = 'https://ACCOUTINGAPP.com/api/v2/orders';
$data = array(
'authtoken' => '***********',
'JSONString' => $jsonInvoice,
'company_id' => '***********'
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded") );
$response = false;
$response = curl_exec($ch);
curl_close($ch);
// TEST RESPONSE
if($response !== false) {
var_dump($response);
}
else
{
echo "oops error hehehe";
}
我主要关心:
我希望用户在进入successpage.php 后立即关闭选项卡或页面。
但我想确保 successpage.php 的 $sendOrder = file_get_contents() 以及它在 sendorder.php 上执行的代码继续运行,无论用户连接如何。
所以我的问题是,我会放在哪里:
ignore_user_abort(TRUE);
另外,我应该使用输出缓冲吗?我只是在问,因为我在其他网站上读到了一篇关于这个的帖子,它建议了这个。
最后,我应该包括:
set_time_limit(0);
Cats萌萌