I have a custom phantomJS procedure which I am calling with the PhantomJS PHP Library. Witht his procedure I want to load the content and extract some information of the rendered page.
The exectration works fine when calling the procedure from command line and logging the "found information" to the console. But now I want to get this information for further processing in my php script.
How to return information from the procedure to the calling php-script?
PHP
$location = '/var/www/vhosts/boos/procs';
$serviceContainer = ServiceContainer::getInstance();
$procedureLoader = $serviceContainer->get('procedure_loader_factory')
->createProcedureLoader($location);
$client = Client::getInstance();
$client->getEngine()->setPath('/usr/local/share/phantomjs/bin/phantomjs');
$client->getEngine()->addOption('--web-security=false');
$client->setProcedure('extractor');
$client->getProcedureLoader()->addLoader($procedureLoader);
$request = $client->getMessageFactory()->createRequest();
$request->setUrl('http://website.de');
$response = $client->getMessageFactory()->createResponse();
$client->send($request, $response);
// GIVE ME THE RESPONSE HERE
Procedure
var page = require('webpage').create();
// settings
page.settings.loadImages = false;
page.settings.localToRemoteUrlAccessEnabled = true;
page.settings.webSecurityEnabled = false;
page.settings.userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36 FirePHP/4Chrome';
page.viewportSize = {
width: 1440,
height: 900
};
t = Date.now();
page.open('{{ input.getUrl() }}', function(status) {
if (status == 'success') {
// Evaluate page
var links = page.evaluate(function() {
// GET ALL LINKS FROM DOM
}
// RETURN THE LINKS TO THE PHP SCRIPT
phantom.exit();
}
});