Curl in php 8.1, apache localhost works but in Bluehost, Nginx, php8.1 fails

187 Views Asked by At

I have a simple test curl function. It works in my localhost apache/php8.1 (Wampserver/windows). It fails in my Bluehost shared server account Nginx/php8.1 I talked to them and they said curl is invoked on their end. The Bluehost PHP.ini file is not viewable by me and they said they could not send it to me to examine.

This worked fine on local and Bluehost when I was on php 7.4. But something may have changed in php8.1?

How can I further test and troubleshoot this code to find the problem?

Another question, why does curl fail when the $curl_url has https rather than http? I have to use only http.

FILE: test_curl.php

    $curl_url = 'http://'.$_SERVER['HTTP_HOST'].'/test_curl_target.php?test_id=999';

    $ch = curl_init($curl_url);
    curl_setopt($ch, CURLOPT_URL, $curl_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_TIMEOUT_MS, 10);      //just some very short timeout
    curl_exec($ch);
    curl_close($ch);

FILE: test_curl_target.php

function log_data($data){//logs data to a file for debugging
  $logPath = $_SERVER["DOCUMENT_ROOT"]."/logs.txt";
  $mode = (!file_exists($logPath)) ? 'w':'a';
  $logfile = fopen($logPath, $mode);
  fwrite($logfile, "\r\n". $data);
  fclose($logfile);
}

log_data('REACHED TARGET PAGE');
$test_id = $_GET['test_id'];
log_data($test_id);

FILE: logs.txt (local machine)

REACHED TARGET PAGE
999

FILE: logs.txt (Bluehost shared server) is always blank

0

There are 0 best solutions below