У меня есть веб-приложение, которое получает уведомления о подключении через Интернет от шлюза оплаты.Все работает несколько хорошо, кроме одной вещи.
Некоторые уведомления (особенно при высокой нагрузке) полностью пропускаются, и я не понимаю, почему.
Я получаю веб-крючок и вставляюданные прямо в очередь для обработки асинхронно.Я не занимаюсь дальнейшей обработкой в самой функции webhook, чтобы убедиться, что веб-соединение оставлено открытым в течение как можно меньшего количества времени.
Странно, у меня есть коллега, который сделал то же самое, но вВанильный PHP, и он не пропускает ни одного из них.Его код обрабатывает webhook, делает несколько проверок, а затем вставляет данные в базу данных, что означает, что веб-соединение остается открытым дольше.
Где я могу ошибаться?Я не получаю ошибок в журнале ошибок.
public function webhook(Request $request) {
$key_from_configuration = '6A36B5F764F50AC55777D370A86333E81D9C0EB94A62553E5D3440EDE1E1A93D';
$iv_from_http_header = $request->header('x-initialization-vector');
$auth_tag_from_http_header = $request->header('x-authentication-tag');
$http_body = file_get_contents('php://input');
$data = array('key' => $key_from_configuration,
'iv' => $iv_from_http_header,
'auth_tag' => $auth_tag_from_http_header,
'cipher' => $http_body);
ProcessTransaction::dispatch(serialize($data));
http_response_code(200);
}
Вот код очереди, в которой я обрабатываю данные:
public function handle() {
$data = unserialize($this->data);
$this->key = hex2bin($data['key']);
$this->iv = hex2bin($data['iv']);
$this->auth_tag = hex2bin($data['auth_tag']);
$this->cipher = hex2bin($data['cipher']);
$this->transaction = openssl_decrypt($this->cipher, 'aes-256-gcm', $this->key, OPENSSL_RAW_DATA, $this->iv, $this->auth_tag);
$psp = new Psp();
$transaction_state = new \stdClass();
$transaction_state->state = 'Live';
$channelApi = new ChannelApi($transaction_state);
$merchantApi = new MerchantApi($transaction_state);
$divisionApi = new DivisionApi($transaction_state);
$decode = json_decode($this->transaction);
$status = ResultCode::where('code', $decode->payload->result->code)->first();
// Get channel, merchant & divisions names/uuid's
$c = $channelApi->getChannel($decode->payload->authentication->entityId);
$c_decode = json_decode($c);
if(!isset($c_decode->channelInfo)) {
$m = $merchantApi->getMerchant($decode->payload->authentication->entityId);
$m_decode = json_decode($m);
$channels = $channelApi->listChannels($m_decode->merchantInfo->id);
$channels_decode = json_decode($channels);
foreach($channels_decode->channels as $item) {
if($item->sender = $m_decode->merchantInfo->id) {
$c = $channelApi->getChannel($item->channel);
$c_decode = json_decode($c);
}
}
}
else {
$m = $merchantApi->getMerchant($c_decode->channelInfo->sender);
$m_decode = json_decode($m);
}
$d = $divisionApi->getDivision($m_decode->merchantInfo->divisionId);
$d_decode = json_decode($d);
$merchant_info = array('channelName' => $c_decode->channelInfo->name, 'channelUuid' => $c_decode->channelInfo->channel,
'merchantName' => $m_decode->merchantInfo->name, 'merchantUuid' => $m_decode->merchantInfo->id,
'divisionName' => $d_decode->divisionInfo->name, 'divisionUuid' => $d_decode->divisionInfo->id);
// If result code is critical, send a text message
$psp->criticalTransaction($decode, $merchant_info);
DB::transaction(function() use ($decode, $status, $c_decode, $m_decode, $d_decode) {
try {
DB::connection('mysql2')->statement('INSERT INTO transactions
(`json`,
`uuid`,
`status`,
`divisionName`,
`divisionUuid`,
`merchantName`,
`merchantUuid`,
`channelName`,
`channelUuid`,
`channelLogin`,
`channelPwd`)
VALUES
(:json_1,
:uuid,
:status_1,
:divisionName,
:divisionUuid,
:merchantName,
:merchantUuid,
:channelName,
:channelUuid,
:channelLogin,
:channelPwd)
ON DUPLICATE KEY UPDATE
`json` = :json_2, `status` = :status_2',
array('json_1' => $this->transaction,
'uuid' => $decode->payload->id,
'status_1' => $status->status,
'divisionName' => $d_decode->divisionInfo->name,
'divisionUuid' => $d_decode->divisionInfo->id,
'merchantName' => $m_decode->merchantInfo->name,
'merchantUuid' => $m_decode->merchantInfo->id,
'channelName' => $c_decode->channelInfo->name,
'channelUuid' => $c_decode->channelInfo->channel,
'channelLogin' => $c_decode->channelInfo->login,
'channelPwd' => $c_decode->channelInfo->pwd,
'json_2' => $this->transaction,
'status_2' => $status->status));
}
catch(Exception $e) {
Storage::prepend('transactions_insert_errors.txt', Carbon::now('UTC')->toDateTimeString()."\nUUID:".$decode->payload->id."\n".$e->getMessage()."\n\n");
throw new Exception($e->getMessage());
}
});
}