I'm currently working on a site to showcase knitting patterns my friend has designed, and part of this site uses cURL reqests to pull down a couple json files from Ravelry's site to display those patterns. When working on it locally, everything works fine without issues or errors, but when I pushed it to a sever this evening, there seems to be problems.
I am running the site on a Vultr server running Ubuntu version 16.04 with PHP version 7.0 and Laravel 5.5. I followed the tutorial from DevMarketer on YouTube to set everything up. I also made sure to install curl and php-curl on the server. Everything is working fine on the live version of the site minus the pattern pages that use json files from the cURL requests.
Below is the part of my controller that makes the cURL requests:
protected function getPatternsList()
{
$login = env('RAVELRY_API_ACCESS_KEY');
$password = env('RAVELRY_API_PERSONAL_KEY');
$url = 'https://api.ravelry.com/patterns/search.json?designer=Handiworks+LTD';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
$result = json_decode(curl_exec($ch));
$patterns = array_reverse($result->patterns);
curl_close($ch);
return $patterns;
}
When I dd $patterns or $results I just end up with null. When I checked the error logs I just got: production.ERROR: Trying to get property of non-object {"exception":"[object] (ErrorException(code: 0): Trying to get property of non-object at /var/www/laravel/app/Http/Controllers/PatternsController.php:22). Line 22 in that file is the line starting with $patterns from above.
I am completely at a loss as to what the issue is, especially since it worked perfectly in a local environment. Any input or suggestions would be greatly appreciated. If any more information about the problem is required to have a better understanding of what is going on, I would be happy to provide it.