I'm creating a PHP-based Google Webfont API for a project and other developers to use. This script is almost one with the exception of a single method that is causing me grief.
I have a method that uses cURL to replace the existing JSON string with a current copy from Google.
public function refreshFontList() {
if(empty($this->publicKey)) {
throw new Exception("API key cannot be empty", 1);
}
// cURL support is needed, test for cURL support before firing
if(!in_array("curl", get_loaded_extensions())) {
if(!init_get("allow_url_fopen")) {
die("Cannot get remote file");
}
} else {
echo "From Google\n";
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => "https://www.googleapis.com/webfonts/v1/webfonts?key=" . $this->publicKey,
CURLOPT_BINARYTRANSFER => TRUE, // for < PHP 5.1.3
CURLOPT_FAILONERROR => TRUE,
CURLOPT_FRESH_CONNECT => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HEADER => FALSE
)
);
var_dump(curl_exec($ch)); // shows as FALSE
curl_close($ch);
}
}
For some reason unknown to me, the ch_exec()
function fails to capture the output of the API call to Google and simply prints boolean(false)
as the output. To better understand the scope of the project, here is the class in its entirety: http://tny.cz/d894e185.
...
$output = curl_exec($ch);
var_dump($output); // still false
...
and
$this->setFontList(ch_exec($ch));
Additionally, I have also disabled all of the options I set for curl_setopt_array
with no avail.
Any assistance is greatly appreciated!
Try it with:
CURLOPT_SSL_VERIFYHOST => FALSE,
CURLOPT_SSL_VERIFYPEER => FALSE,
Further information: