I have an apache server with centos distribution that I have put a PHP Laravel project on using git. It uses cURL requests to fetch and execute data gotten from endpoints. When I run this on my local virtual machine, it works perfectly. When I run it on my
Here is my code, note the cURL requests:
//NOTE: $this->headers = ["Authorization: Bearer " . myServerAccessToken];
//sets URL and $curl
public function getAdmins() {
$adminsURL = "https://my.test.instructure.com/api/v1/accounts/1/admins?per_page=20";
$curl = curl_init();
self::requestCurl($curl, $adminsURL, $this->headers);
$resp = curl_exec($curl);
//dd($resp); //shows false
return self::setHeaders($curl);
}
//cURL request function: used to set the value of $curl as seen in other functions
public function requestCurl($curl, $url, $headers) {
return curl_setopt_array($curl, [
CURLOPT_RETURNTRANSFER => TRUE,
CURLINFO_HEADER_OUT => TRUE,
CURLOPT_URL => $url,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYPEER => TRUE,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_FOLLOWLOCATION => TRUE,
CURLOPT_MAXREDIRS => 10,
CURLOPT_HEADER => TRUE
]);
}
//returns "curl errno: 0. Failed to connect to my.test.instructure.com:443; Operation now in progress
//gets the data from a successful curl request, and returns said data
public function setHeaders($curl) {
echo "<h1>SetHeaders()</h1>";
$resp = curl_exec($curl);
$header_size = curl_getinfo( $curl, CURLINFO_HEADER_SIZE );
$header = substr( $resp, 0, $header_size );
$body = substr( $resp, $header_size); //$header_size
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if (curl_getinfo($curl, CURLINFO_HTTP_CODE) != 200) {
echo "<h3>Curl errno: " . curl_getinfo($curl, CURLINFO_HTTP_CODE) . "</h3>";
echo "<h3>Curl error(): " . curl_error($curl) . "</h3>";
dd($body);
return null;
}
$data = json_decode($body, true);
return $data;
}
I can run this code on my local machine and it works perfectly. No complaints, full success. But when I run it on my apache server with a centos distribution, it falls apart. This output is what I get instead:
"SetHeaders()"
"Curl errno: 0"
"Curl error(): Failed connect to my.test.instructure.com:443; Operation now in progress""" [dd($body) returns an empty string]
====
I've looked up currl errno: 0 and I've looked up curl error 443, but The closest I've seen to a problem similar to mine is this page here:
But from what I can tell, I already have the suggested solution in my code (CURLOPT_FOLLOWLOCATION => TRUE).
I suspect the problem is with the server itself, but I do not know enough of it to say what. I have looked at the /etc/hosts folder on my server, but I've been told it is configured correctly. With that in mind, what more can I try to solve this problem?