In this article, I will share with you how to send POST cURL requests without waiting for a response with an example.
Currently, I was work with one big laravel application and in this application, we need to send webhook POST data on the merchant's notification POST url. before I write POST webhook which waiting response from the merchant side. so, it takes more time to execute. it's ok with the small amount of data. but what happened if you play with a big amount of data? then this logic not working and your application should not be working fast. so, i search on google and make a very simple solution for it. so, I share with you how to make a fire and forget POST requests in cURL.
function postCurlRequest(string $url, array $post_array, $check_ssl=true) {
$cmd = "curl -L -X POST -H 'Content-Type: application/json'";
$cmd.= " -d '" . json_encode($post_array) . "' '" . $url . "'";
if (!$check_ssl){
$cmd.= "' --insecure"; // this can speed things up, though it's not secure
}
$cmd .= " > /dev/null 2>&1 &"; // don't wait for response
// echo $cmd;die;
exec($cmd, $output, $exit);
return $exit == 0;
}
$data = [
'order_no' => date('Y').rand(11111,99999).time(),
'product_name' => 'products-1',
'price' => 100,
'currency' => 'USD',
];
$url = 'https://your_post_url.com';
$response = postCurlRequest($url, $data);
var_dump($response);
i hope you like this article.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Laravel 8 Generate Fake Data Using Faker Example
Sometimes you are testing project in loc...Start Applications Automatically on Login in Ubuntu
Many of us need to open certain applicat...How to explode or split a string in JavaScript
Use the JavaScript split() method If...How to call a function repeatedly after fixed time interval in jQuery
Use the JavaScript setInterval() method...Sending Telegram Notifications in Laravel
Telegram is a highly customizable,...