0

The following code works when I use the URL to some external like stackoverflow in the example below

<?php
$url = 'https://stackoverflow.com/questions/12781876/get-file-content-via-php-curl';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
echo $data;
curl_close($curl);

The problem is when I call my local server url

$url="https://example.com/apiv1.php?test=abc&pet=ss"; It throws error

cURL Error #:Connection timed out after 30000 milliseconds

My API code looks like this

<?php
echo "ACCEPTED";
?>

And please I tried increasing the PHP timeout, I tried setting the timeout in CURL as well nothing works

Sometimes it throws an error

cURL Error #:Failed to connect to mydomain.com port 443: Connection timed out
user580950
  • 3,558
  • 12
  • 49
  • 94

1 Answers1

0

Try this :

$url = 'https://stackoverflow.com/questions/12781876/get-file-content-via-php-curl';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 0);
curl_setopt($curl, CURLOPT_HEADER, false);
$data = curl_exec($curl);
echo $data;
curl_close($curl);