1

我正在使用 PHP 脚本来访问 Gracenote 的 WEB API。虽然它有时会起作用,但大多数时候它会给我一个超时错误。这是我得到的错误:

异常:代码=2001,消息=对 Gracenote WebAPI 的请求超时。,ext=PHP 致命错误:未捕获的异常“Gracenote\WebAPI\GNException”,消息“对 Gracenote WebAPI 的请求超时。” 在 /home/kubuntu/Downloads/php-gracenote-master/php-gracenote-master/php-gracenote/HTTP.class.php:1

这是我非常简单的代码:

<?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);

做错了什么?

4

3 回答 3

1

我遇到了同样的问题,每 10 个请求中的 9 个连接都会超时,并出现以下错误:

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    

原因(我怀疑)是 curl 连接缺少 SSL 选项参数。

通过将其添加到 HTTP.class.php 的第 38 行,我能够永久修复。

    curl_setopt($this->_ch, CURLOPT_SSLVERSION,     3);
于 2014-08-31T12:18:29.717 回答
1

正如 Yavor 所建议的,问题与服务器上的 SSL 设置有关。但是我们现在添加了对 TLS v1.2 的完全支持,因此您的原始代码应该可以使用默认的 SSL 设置。

由于 POODLE 漏洞,您不应使用 SSL v3。

于 2014-10-17T05:29:38.260 回答
0

您应该使用 try/catch 来包围 Gracenote api 调用,gracenote HTTP 客户端会抛出各种异常

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

于 2014-08-14T03:19:53.807 回答