Sto provando a utilizzare phantomJS per acquisire uno screenshot di un URL, tuttavia quando chiamo phantomJS (dalla riga di comando o dall'app Web) si blocca e vedem non eseguire mai il " exit() "chiama. Non riesco a trovare alcun messaggio di errore e rimane in esecuzione fino a quando non lo uccido. Questo è il file JS che viene passato al comando phantomjs:PhantomJS in attesa quando chiamato da CLI o Web
var page = require('webpage').create();
var system = require('system');
var script_address = '';
var page_to_load = '';
var members_id = '';
var activities_id = '';
var folder_path = '';
if (system.args.length < 5)
{
console.log('Usage: phantom_activity_fax.js script_address page_to_load members_id activities_id folder_path');
console.log('#Args: '+system.args.length);
phantom.exit();
}//END IF SYSTEM.ARGS.LENGTH === 1
//ASSIGN OUR ARGUMENTS RECIEVED
script_address = system.args[0];
page_to_load = system.args[1];
members_id = system.args[2];
activities_id = system.args[3];
folder_path = system.args[4];
console.log(system.args[0]);
console.log(system.args[1]);
console.log(system.args[2]);
console.log(system.args[3]);
console.log(system.args[4]);
//OPEN OUR PAGE WITH THE VALUES PROVIDED
page.open(page_to_load, function() {
console.log("Entering Anonymous Function, Beginning RENDER:\n");
page.render(folder_path+members_id+'_'+activities_id+'.png');
phantom.exit();
});
vedo i valori hanno spinto alla console, ma dopo che si blocca appena :(ho provato l'ispettore web, ma non riusciva a capire dove per eseguire la chiamata __run() e non ho visto alcuna modifica quando ho aggiunto il debugger-autorun = yes alla chiamata :(.
Questo è l'output che ottengo dalla riga di comando quando si blocca (come root utente):
[[email protected] faxes]# phantomjs /var/www/wv-wellvibe2-test/javascripts/phantom_activity_fax.js https://wv-wellvibe2-test/manual_scripts/phantom_js_test_page.php 397 0 /var/www/wv-wellvibe2-test/uploads/images/faxes/
/var/www/wv-wellvibe2-test/javascripts/phantom_activity_fax.js
https://wv-wellvibe2-test/manual_scripts/phantom_js_test_page.php
397
0
/var/www/wv-wellvibe2-test/uploads/images/faxes/
E questa è l'uscita ottengo quando si esegue come il mio utente, ma io don 'T vedere il file immagine nella cartella designata (fax):
[[email protected] ~]$ phantomjs /var/www/wv-wellvibe2-test/javascripts/phantom_activity_fax.js https://wv-wellvibe2-test/manual_scripts/phantom_js_test_page.php 397 0 /var/www/wv-wellvibe2-test/uploads/images/faxes/
/var/www/wv-wellvibe2-test/javascripts/phantom_activity_fax.js
https://wv-wellvibe2-test/manual_scripts/phantom_js_test_page.php
397
0
/var/www/wv-wellvibe2-test/uploads/images/faxes/
Entering Anonymous Function, Beginning RENDER:
[[email protected] ~]$
Purtroppo, come ho detto, il comando è stato completato, ma non ha salvato un .png nella cartella dei fax. Ecco i permessi per quella cartella:
[[email protected] faxes]# ls -la
total 12
drwxr-xr-x 3 root apache 4096 May 16 15:31 .
drwxr-xr-x 5 apache apache 4096 May 16 14:14 ..
drwxr-xr-x 6 apache apache 4096 May 20 15:05 .svn
Per favore fatemi sapere se c'è qualcos'altro che posso fornire! Grazie!
(Come richiesto ecco lo script PHP che chiama il processo di Phantom JS)
header("Date: " . date('Y-m-d H:i:s'));
//GET THE SMARTY CONFIG
include_once $_SERVER['DOCUMENT_ROOT'] . "/smarty/configs/config.php";
//VARS USED LATER
$process_script = $_SERVER['DOCUMENT_ROOT'] . '/javascripts/phantom_activity_fax.js';
$page_to_load = 'https://' . $_SERVER['HTTP_HOST'] . '/manual_scripts/phantom_js_test_page.php';
$members_id = $_SESSION['members_id'];
$activities_id = 0;
$folder_path = $_SERVER['DOCUMENT_ROOT'] . 'uploads/images/faxes/';
$system_response = '';
$call = "phantomjs --remote-debugger-port=65534 --remote-debugger-autorun=yes " . $process_script . " " . $page_to_load . " " . $members_id . " " . $activities_id . " " . $folder_path;
echo 'CallingSystemWith: ' . $call . '<br />';
try
{
$system_response = system($call);
echo '<br />SystemResponse: ' . $system_response . '<hr />';
} catch (Exception $exc) {
echo $exc->getTraceAsString();
}//END TRY/CATCH
(la pagina racconta PhantomJS a "raschiare" è un semplice script PHP che outtputs un print_r() di $ _SESSION e $ _REQUEST)
Grazie per la risposta! Ho aggiunto il try/catch e i gestori onError allo script e lo script viene eseguito sulla riga di comando (salvando un file PNG vuoto). Tuttavia si blocca ancora quando vi si accede tramite il browser web. Qualche idea sul perché si blocca sul web? – Danoweb
vuoto PNG? Sembra che ci sia un errore in page.open o con l'url. Come si esegue lo script tramite il browser Web? percorso exec non valido? prova ad accedere a un file. – Cybermaxs
Grazie alle aggiunte che mi hai fatto fare, ho scoperto il riagganciare! Risulta che PhantomJS non sostituisce un file (come l'impostazione predefinita di PHP). Dopo aver rimosso il file immagine e riavviato non riesco più a riagganciare! Grazie Cybermaxs! – Danoweb