I would like to cancel a cURL request. The request should be cancelled when the user is leaving the page.
Explanation of the situation: we're sending a cURL request to a mobile payment terminal to start a new payment. The request is still pending since we're waiting for the customer to enter the pin code. When the pin code is entered, the request will be answered with success / failure. We would like to cancel the request from the server to the payment terminal when, for example, the customer would like to pay in cash.
We've tried different approaches, e.g. connection_aborted
& ignore_user_abort
but nothing will fix the job.
$dataString = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($dataString)
));
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_SSLCERT, certificateRoot.'/test.crt.pem');
curl_setopt($ch, CURLOPT_SSLKEY, certificateRoot.'/test.key.pem');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);