Question

WHen I run this script from cmd.exe [command line] on WAMP I get:

 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:

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?

P.S. Open Amplify is a web service which takes the text provided and after analysing it, returns alot of interesting things about it. 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!

Was it helpful?

Solution

To extend the timeout, you can use the 'timeout' name/value pair inside of the 'http' options. E.g. put it under here:

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

(Reference: http://www.php.net/manual/en/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. At least from that point you will be debugging the network issue, and not 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).

OTHER TIPS

try hitting this url. This should work http://portaltnx20.openamplify.com/AmplifyWeb_v21/AmplifyThis

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top