1

I am using a PHP script to access the WEB API of gracenote. Though it works sometimes, it gives me a time out error most of the times. Here is the error I am getting:

exception: code=2001, message=Request to a Gracenote WebAPI timed out., ext= PHP Fatal error: Uncaught exception 'Gracenote\WebAPI\GNException' with message 'Request to a Gracenote WebAPI timed out.' in /home/kubuntu/Downloads/php-gracenote-master/php-gracenote-master/php-gracenote/HTTP.class.php:1

Here is my very simple code:

<?php
include("./php-gracenote/Gracenote.class.php");

$clientID  = ""; 
$clientTag = ""; 

$api = new Gracenote\WebAPI\GracenoteWebAPI($clientID, $clientTag); 
$userID = "xxxxxxxxxxxxxxxxxx";
echo "UserID = ".$userID."\n";

$results = $api->searchArtist("Bob Dylan");
var_dump($results);

What am doing wrong?

Akshay
  • 13
  • 2

3 Answers3

1

I had the same issue where every 9 out of 10 requests the connection would time out with the following error:

http: external request POST url=https://1234567.web.cddbp.net/webapi/xml/1.0/, timeout=20000 exception: code=2001, message=Request to a Gracenote WebAPI timed out., ext=0 
Fatal error: Uncaught exception 'Gracenote\WebAPI\GNException' with message 'Request to a 
Gracenote    WebAPI timed out.' in /usr/samba/dev/gracenote/php-gracenote/php-  
gracenote/HTTP.class.php:110 Stack trace: #0 /usr/samba/dev/gracenote/php-gracenote/php-
gracenote/HTTP.class.php(94): Gracenote\WebAPI\HTTP->validateResponse(false) #1 
/usr/samba/dev/gracenote/php-gracenote/php-gracenote/HTTP.class.php(144): Gracenote\WebAPI\HTTP-
>execute() #2 /usr/samba/dev/gracenote/php-gracenote/php-gracenote/Gracenote.class.php(59): 
Gracenote\WebAPI\HTTP->post('<QUERIES>? ...') #3 /usr/samba/dev/gracenote/php-
gracenote/example.php(31): Gracenote\WebAPI\GracenoteWebAPI->register() #4 {main} thrown in 
/usr/samba/dev/gracenote/php-gracenote/php-gracenote/HTTP.class.php on line 110    

The reason ( i suspect) is the missing SSL option parameter for the curl connection.

I was able to fix permanently by adding this to line 38 in HTTP.class.php.

    curl_setopt($this->_ch, CURLOPT_SSLVERSION,     3);
Yavor
  • 675
  • 4
  • 20
1

As suggested by Yavor, the problem had to do with SSL settings on the server. But we have now added full support for TLS v1.2, so your original code should work with the default SSL settings.

You should not use SSL v3 because of the POODLE vulnerability.

cweichen
  • 493
  • 3
  • 5
0

You should use try/catch to surround gracenote api calls, gracenote HTTP client throws various of exceptions

e.g. https://github.com/richadams/php-gracenote/blob/25e0346443dd5026a4bc9f0d62a589d44bdc133b/php-gracenote/HTTP.class.php#L110

Xuphey
  • 50
  • 5
  • Thanks, it solved the problem. It takes a lot of exceptions though to finally work. – Akshay Aug 15 '14 at 01:59
  • Actually the code doesn't crash now but still it takes forever to produce results. I think there is something very wrong with how I am accessing the data. – Akshay Aug 15 '14 at 02:40