相关疑难解决方法(0)

从php启动phantomjs服务器并等待它的响应

我想从我的php脚本运行一个phantomjs服务器,然后对它进行curl请求并读取它的响应(在最终版本中将给出生成pdf的路径).从控制台运行phantomjs服务器文件,然后在浏览器中导航到它的地址时,一切正常.这是server.js文件:

var server, service, page = require('webpage').create(), address, output,
    html = '<!DOCTYPE><html><head></head><body><h1>FOOO</h1></body></html>';

server = require('webserver').create();

var rasterize = function(html, callback){
    address = 'http://localhost';
    output = '/Users/me/print.pdf'
    page.viewportSize = { width: 600, height: 600 };
    page.open(address, function (status) {
        if (status !== 'success') {
            console.log('Unable to load the address!');
        } else {
            window.setTimeout(function () {
                page.content = html;
                page.render(output);
                callback();
            }, 2000);
        }
    });
}

service = server.listen(8080, function (request, response) {
    response.statusCode = 200;

    rasterize(html, function(){
        response.write('<h1>BAR</h1>');
        response.close();
        phantom.exit();     
    }); …
Run Code Online (Sandbox Code Playgroud)

javascript php shell curl phantomjs

8
推荐指数
1
解决办法
8532
查看次数

标签 统计

curl ×1

javascript ×1

phantomjs ×1

php ×1

shell ×1