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 harsukh21@gmail.com
How to get current image size (width & height) in javascript
Use the JavaScript clientWidth ...How to animate div width on mouse hover using jQuery
Use the jQuery animate() method You c...How to check whether a value is numeric or not in jQuery
Use the jQuery.isNumeric() method You...How to compare two array values in PHP
Use the PHP array_diff() funct...How to change OLD Password with Validation in Laravel
Here, i will show you old password valid...