简体   繁体   English

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

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

WHen I run this script from cmd.exe [command line] on WAMP I get: 当我在WAMP上从cmd.exe [command line]运行此脚本时,我得到:

 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)

When I run this script from localhost via firefox browser [v 19.0] I get: 当我通过Firefox浏览器[v 19.0]从本地主机运行此脚本时,得到:

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

Here is the script I used: 这是我使用的脚本:

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


?>

How can I make this work? 我该如何进行这项工作?

PS Open Amplify is a web service which takes the text provided and after analysing it, returns alot of interesting things about it. PS Open Amplify是一个Web服务,接受提供的文本,并在对其进行分析之后,返回有关它的许多有趣的信息。 I am really keen on making this work and big fan of QueryPath, so I am only interested in suggestions on how to make it work with QueryPath! 我真的很热衷于使这项工作成为QueryPath的忠实拥护者,所以我只对有关如何使其与QueryPath一起使用的建议感兴趣!

try hitting this url. 尝试点击此网址。 This should work http://portaltnx20.openamplify.com/AmplifyWeb_v21/AmplifyThis 这应该可以使用http://portaltnx20.openamplify.com/AmplifyWeb_v21/AmplifyThis

To extend the timeout, you can use the 'timeout' name/value pair inside of the 'http' options. 要延长超时时间,可以在“ http”选项中使用“超时”名称/值对。 Eg put it under here: 例如放在这里:


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

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

My guess, though, is that something else is amiss. 不过,我的猜测是还有其他问题。 You might use file_get_contents() instead of qp() to fetch the file, and then pass the string into QueryPath. 您可以使用file_get_contents()而不是qp()来获取文件,然后将字符串传递到QueryPath中。 At least from that point you will be debugging the network issue, and not QueryPath. 至少从那时起,您将调试网络问题,而不是QueryPath。

For working with OpenAmplify, I've also had great luck with using the CURL API, but that is a little more complex than the built-in PHP stream wrapper (Reference: http://www.php.net/manual/en/book.curl.php ). 对于使用OpenAmplify,我也很幸运使用CURL API,但这比内置的PHP流包装器要复杂一些(参考: http : //www.php.net/manual/zh/ book.curl.php )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM