从QueryPath访问OpenAmplify时,我的HTTP请求失败/超时.为什么


When Accessing OpenAmplify from QueryPath my HTTP request fails/times out. Why?

WHen我从WAMP上的cmd.exe[命令行]运行此脚本时,我得到:

 Could not retrieve data from OpenAmplify.file_get_contents(http://portal
tnx.openamplify.com/AmplifyWeb/AmplifyThis?apiKey=MY_API_KEY_GOES_HERE): failed to open stream: HTTP request failed!  (C:'wamp'www'Learning_Query_Pa
th'src'QueryPath'QueryPath.php: 4053)

当我通过firefox浏览器[v19.0]从localhost运行此脚本时,我得到:

Fatal error: Maximum execution time of 30 seconds exceeded in C:'wamp'www'Learning_Query_Path'src'QueryPath'QueryPath.php on line 4525

这是我使用的脚本:

    <?php
require 'src/QueryPath/QueryPath.php';
$url = 'http://portaltnx.openamplify.com/AmplifyWeb/AmplifyThis?';
$key = 'I_PUT_MY_API_KEY_HERE';
$text = 'I_PUT_TEXT_HERE';
$params = array(
  'apiKey' => $key,
);
$url .= http_build_query($params);
$options = array(
  'http' => array(
    'method' => 'POST',
    'user_agent' => 'QueryPath/2.0',
    'header'  => 'Content-type: application/x-www-form-url-encoded',
    'content' => http_build_query(array('inputText' => $text)),
  ),
);
$context = stream_context_create($options);
try {
  $qp = qp($url, NULL, array('context' => $context));
}
catch (Exception $e) {
  print "Could not retrieve data from OpenAmplify." . $e->getMessage();
  exit;
}
    $qp->find('ProperNouns>TopicResult>Topic>Name')->slice(0, 20);

$out = qp(QueryPath::HTML_STUB, 'body')->append('<ul/>')->find('ul');

foreach ($qp as $name) {
  $out->append('<li>' . $name->text() . '</li>');
}
$out->writeHTML();

?>

我怎样才能做到这一点?

第页。S.Open Amplify是一个web服务,它接受所提供的文本,并在分析后返回许多有趣的东西。我真的很想让它发挥作用,也是QueryPath的忠实粉丝,所以我只对如何让它与QueryPath一起工作的建议感兴趣!

要延长超时时间,可以在"http"选项中使用"timeout"名称/值对。例如,把它放在下面:

'content' => ...
'timeout' => 120.0

(参考:http://www.php.net/manual/en/context.http.php)

不过,我的猜测是出了什么问题。您可以使用file_get_contents()而不是qp()来获取文件,然后将字符串传递到QueryPath中。至少从那时起,您将调试网络问题,而不是QueryPath。

对于使用OpenAmplify,我也很幸运地使用了CURL API,但这比内置的PHP流包装器稍微复杂一些(参考:http://www.php.net/manual/en/book.curl.php)。

尝试点击此url。这应该有效http://portaltnx20.openamplify.com/AmplifyWeb_v21/AmplifyThis