Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ali2535's avatar

Curl in PHP and Laravel

why follow code not work ?

$json_data = json_encode($data); $curl = curl_init($url); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); curl_setopt($curl, CURLOPT_POSTFIELDS, $json_data); $curl_response = curl_exec($curl); dd($curl_response );

time is very much for execute this code. why?

0 likes
2 replies
shakti's avatar

you can use something like this to check your error

if(curl_exec($ch) === false)
{
    echo 'Curl error: ' . curl_error($ch);
}
else
{
    echo 'Operation completed without any errors';
}
ali2535's avatar

time to execute request is very long for examle when i get www.example.com data it is ok and time ok

but when i get from mysite.com/api/v1/getdata it is very long time .

Please or to participate in this conversation.