首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >从命令行界面或Web调用时PhantomJS挂起

从命令行界面或Web调用时PhantomJS挂起
EN

Stack Overflow用户
提问于 2013-05-21 04:24:44
回答 1查看 13.9K关注 0票数 17

我正在尝试使用phantomJS来捕获网址的屏幕截图,但是当我调用phantomJS (从命令行或web应用程序)时,它挂起并看到永远不会执行"exit()“调用。我似乎找不到任何错误消息,并且它一直在运行,直到我杀死它。这是传递给phantomjs命令的JS文件:

代码语言:javascript
复制
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();
});

我看到值被推送到控制台,但之后它就挂起了:(我尝试了web检查器,但不知道在哪里执行__run()调用,当我将调试器-autorun=yes添加到调用中时,没有看到任何变化:(。

这是我在命令行挂起时(以root用户身份)获得的输出:

代码语言:javascript
复制
[root@wv-wellvibe2 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/

这是我作为自己的用户运行它时得到的输出,但我在指定的文件夹(传真)中看不到图像文件:

代码语言:javascript
复制
[user@wv-wellvibe2 ~]$ 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:
[user@wv-wellvibe2 ~]$ 

不幸的是,正如我所说的,该命令已完成,但没有在faxes文件夹中保存.png。下面是该文件夹的权限:

代码语言:javascript
复制
[root@wv-wellvibe2 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

如果还有什么我能提供的,请告诉我!谢谢!

(这里请求的是调用Phantom JS流程的PHP脚本)

代码语言:javascript
复制
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

(它告诉PhantomJS“抓取”的页面是一个简单的PHP脚本,它输出$_SESSION和$_REQUEST的print_r() )

EN

回答 1

Stack Overflow用户

发布于 2015-10-29 22:03:51

使用:

代码语言:javascript
复制
$phantomjs --debug=true rasterize.js http://... test.pdf

在rasterize.js中,在ressource上添加超时,这是我的问题:

代码语言:javascript
复制
page.settings.resourceTimeout = 10000; // Avoid freeze!!!
票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16657744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档