jonnnnyw / php-phantomjs

Execute PhantomJS commands through PHP
MIT License
1.44k stars 432 forks source link

Empty Response - phantomjs 2.1.1 #179

Open lucaele opened 7 years ago

lucaele commented 7 years ago

Hi all, i'm using php phantomjs with phantomjs 2.1.1 (downloaded from http://phantomjs.org/download.html).

I follow all guide, but still response is empty. Same with phantomjs 1.9.8

Any idea? Thanks

Response is empty: JonnyW\PhantomJs\Http\Response Object ( [headers] => Array ( ) [status] => [content] => [contentType] => [url] => [redirectURL] => [time] => [console] => [cookies] => )

My php script `require DIR . '/vendor/autoload.php';

use JonnyW\PhantomJs\Client; use JonnyW\PhantomJs\DependencyInjection\ServiceContainer;

$client = Client::getInstance(); $client->getEngine()->setPath(dirname(FILE).'/bin/phantomjs'); echo $client->getEngine()->getPath()."
"; $client->getProcedureCompiler()->disableCache();

$location = 'proc/';

$serviceContainer = ServiceContainer::getInstance(); $procedureLoader = $serviceContainer->get('procedure_loader_factory') ->createProcedureLoader($location); $client->getProcedureLoader()->addLoader($procedureLoader);

$request = $client->getMessageFactory()->createRequest(); $client->setProcedure('wisdom'); // nome file senza estensione $response = $client->getMessageFactory()->createResponse();

$client->send($request, $response); if (($response->getStatus() === 200) || ($response->getStatus() == 'success')){ // Dump the requested page content echo "Right...
"; print_r($response); echo "
";

echo "<br>Status = ".$response->getStatus();
echo "<br>Content = ".$response->getContent();
echo $response->getConsole();

} else { echo "Problem: ".$response->getStatus(); } `

My .proc `phantom.onError = function (msg, trace) { console.log(JSON.stringify({ "status": msg })); phantom.exit(1); };

var system = require('system'); var uri = "https://www.google.com";

var page = require('webpage').create(); var response = {}, debug = [], logs = [], procedure = {};

page.settings.userAgent = 'SpecialAgent'; page.open(uri, function (status) { console.log(JSON.stringify({ "status": status }));

if (status === "success") {
    var ua = page.evaluate(function() {
      return document.getElementById('footer').textContent;
    });
    console.log(JSON.stringify({
      "status": ua
    }));
}
phantom.exit(1);

});`

etudor commented 7 years ago

@lucaele try running my.proc with phantomjs directly and check what errors you get.

bin/phantomjs --debug=true proc/my.proc

Also, in your example, you have an error. You procedure file name is my.proc but you are setting $client->setProcedure('wisdom');. Either name the file wisdom.proc or $client->setProcedure('my'); Procedure file name should match with the procedure name you set.