I am calling data from an API like this:
$curl = curl_init(); //adding fields to the curl object to enter the site curl_setopt($curl, CURLOPT_URL, $my_url); curl
Not sure why is not working for you. When the json string is in the code it does work.
Ouput:
1 Books
Btw my version
PHP 5.6.30 (cli) (built: Aug 8 2017 12:20:45)