highcharts / node-export-server

Highcharts Node.js export server
Other
356 stars 260 forks source link

Execution via PHP exec has stopped working. #347

Closed jarrettj closed 1 year ago

jarrettj commented 2 years ago

Hey all,

Good day.

Expected behaviour

Should generate image file the same as when running the command on the cli.

The command is straight forward. And as I said, had been working before.

$command = "export OPENSSL_CONF=\$WORKSPACE/openssl.cnf && highcharts-export-server -infile {$optionsFilename} -outfile {$chartFilename} --scale $scale --allowCodeExecution true";
exec($command, $output, $result);

The json file:

{
    "chart": {
        "plotBorderWidth": 1,
        "borderRadius": 20,
        "borderColor": '#0E2197',
        "borderWidth" : 1
    },
    "navigation": {
        "buttonOptions": {
            "enabled": false
        }
    },
    "colors": ["#2f7ed8","#90ed7d","#f7a35c","#e4d354","#1aadce"],
    "title": {
    "text": "Test by Segment"
    },
    "subtitle": {
        "text": "Source: Test Analytics"
    },
    "credits": {
        "enabled": false
    },
    "plotOptions": {
        "pie": {
            "dataLabels": {
                "enabled": true,
                "useHTML": true,
                "padding": 0,
                "format": "{point.name}: {point.y} <span style='color:#808080'>({point.previousY})</span>",
                "allowOverlap": true,
                "style": {
                    "fontSize": '11px'
                }
            }
        }
    },
    "series": [{
        "type": "pie",
        "name": "Cases by segment",
        "data": [{"name":"Test 1","y":1762,"id":40,"previousY":1269,"sliced":true,"selected":true},{"name":"Test 2","y":23,"id":6,"previousY":23},{"name":"Test 4","y":5,"id":13,"previousY":4},{"name":"Test 5","y":4,"id":35,"previousY":4},{"name":"Test 3","y":2,"id":37,"previousY":2}]    }]
}

Actual behaviour

Throws a syntax error:

[13] => Thu May 26 2022 14:40:20 GMT+0000 (Coordinated Universal Time) [error] phantom worker 1 unexpected data - SyntaxError: Expected token ')'
    [14] => 
    [15] =>   phantomjs://code/worker.js:658 in loop
    [65] =>     svgstr: undefined,
    [66] =>     format: 'png',
    [67] =>     out: 'tmp/pchart3.png',
    [68] =>     styledMode: false,
    [69] =>     asyncRendering: undefined,
    [70] =>     async: true,
    [71] =>     reqID: '',
    [72] =>     globalOptions: false,
    [73] =>     themeOptions: false,
    [74] =>     customCode: false,
    [75] =>     dataOptions: false,
    [76] =>     id: 1
    [77] =>   },
    [78] =>   working: true,
    [79] =>   ready: false,
    [80] =>   alive: true,
    [81] =>   process: ChildProcess {
    [82] =>     _events: [Object: null prototype] {
    [83] =>       uncaughtException: [Function],
    [84] =>       error: [Function],
    [85] =>       close: [Function]
    [86] =>     },
    [87] =>     _eventsCount: 3,
    [88] =>     _maxListeners: undefined,
    [89] =>     _closesNeeded: 3,
    [90] =>     _closesGot: 0,
    [91] =>     connected: false,
    [92] =>     signalCode: null,
    [93] =>     exitCode: null,
    [94] =>     killed: false,
    [95] =>     spawnfile: '/home/node/.npm-global/lib/node_modules/highcharts-export-server/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs',
    [96] =>     _handle: Process {
    [97] =>       onexit: [Function],
    [98] =>       pid: 25964,
    [99] =>       [Symbol(owner_symbol)]: [Circular]
    [100] =>     },
    [101] =>     spawnargs: [
    [102] =>       '/home/node/.npm-global/lib/node_modules/highcharts-export-server/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs',
    [103] =>       '/home/node/.npm-global/lib/node_modules/highcharts-export-server/lib/../phantom/worker.js',
    [104] =>       '/home/node/.npm-global/lib/node_modules/highcharts-export-server/lib/../'
    [105] =>     ],
    [106] =>     pid: 25964,
    [107] =>     stdin: Socket {
    [108] =>       connecting: false,
    [109] =>       _hadError: false,
    [110] =>       _parent: null,
    [111] =>       _host: null,
    [112] =>       _readableState: [ReadableState],
    [113] =>       readable: false,
    [114] =>       _events: [Object: null prototype],
    [115] =>       _eventsCount: 1,
    [116] =>       _maxListeners: undefined,
    [117] =>       _writableState: [WritableState],
    [118] =>       writable: true,
    [119] =>       allowHalfOpen: false,
    [120] =>       _sockname: null,
    [121] =>       _pendingData: null,
    [122] =>       _pendingEncoding: '',
    [123] =>       server: null,
    [124] =>       _server: null,
    [125] =>       [Symbol(asyncId)]: 7,
    [126] =>       [Symbol(kHandle)]: [Pipe],
    [127] =>       [Symbol(kSetNoDelay)]: false,
    [128] =>       [Symbol(lastWriteQueueSize)]: 0,
    [129] =>       [Symbol(timeout)]: null,
    [130] =>       [Symbol(kBuffer)]: null,
    [131] =>       [Symbol(kBufferCb)]: null,
    [132] =>       [Symbol(kBufferGen)]: null,
    [133] =>       [Symbol(kCapture)]: false,
    [134] =>       [Symbol(kBytesRead)]: 0,
    [135] =>       [Symbol(kBytesWritten)]: 0
    [136] =>     },
    [137] =>     stdout: Socket {
    [138] =>       connecting: false,
    [139] =>       _hadError: false,
    [140] =>       _parent: null,
    [141] =>       _host: null,
    [142] =>       _readableState: [ReadableState],
    [143] =>       readable: true,
    [144] =>       _events: [Object: null prototype],
    [145] =>       _eventsCount: 3,
    [146] =>       _maxListeners: undefined,
    [147] =>       _writableState: [WritableState],
    [148] =>       writable: false,
    [149] =>       allowHalfOpen: false,
    [150] =>       _sockname: null,
    [151] =>       _pendingData: null,
    [152] =>       _pendingEncoding: '',
    [153] =>       server: null,
    [154] =>       _server: null,
    [155] =>       [Symbol(asyncId)]: 8,
    [156] =>       [Symbol(kHandle)]: [Pipe],
    [157] =>       [Symbol(kSetNoDelay)]: false,
    [158] =>       [Symbol(lastWriteQueueSize)]: 0,
    [159] =>       [Symbol(timeout)]: null,
    [160] =>       [Symbol(kBuffer)]: null,
    [161] =>       [Symbol(kBufferCb)]: null,
    [162] =>       [Symbol(kBufferGen)]: null,
    [163] =>       [Symbol(kCapture)]: false,
    [164] =>       [Symbol(kBytesRead)]: 0,
    [165] =>       [Symbol(kBytesWritten)]: 0
    [166] =>     },
    [167] =>     stderr: Socket {
    [168] =>       connecting: false,
    [169] =>       _hadError: false,
    [170] =>       _parent: null,
    [171] =>       _host: null,
    [172] =>       _readableState: [ReadableState],
    [173] =>       readable: true,
    [174] =>       _events: [Object: null prototype],
    [175] =>       _eventsCount: 3,
    [176] =>       _maxListeners: undefined,
    [177] =>       _writableState: [WritableState],
    [178] =>       writable: false,
    [179] =>       allowHalfOpen: false,
    [180] =>       _sockname: null,
    [181] =>       _pendingData: null,
    [182] =>       _pendingEncoding: '',
    [183] =>       server: null,
    [184] =>       _server: null,
    [185] =>       [Symbol(asyncId)]: 9,
    [186] =>       [Symbol(kHandle)]: [Pipe],
    [187] =>       [Symbol(kSetNoDelay)]: false,
    [188] =>       [Symbol(lastWriteQueueSize)]: 0,
    [189] =>       [Symbol(timeout)]: null,
    [190] =>       [Symbol(kBuffer)]: null,
    [191] =>       [Symbol(kBufferCb)]: null,
    [192] =>       [Symbol(kBufferGen)]: null,
    [193] =>       [Symbol(kCapture)]: false,
    [194] =>       [Symbol(kBytesRead)]: 0,
    [195] =>       [Symbol(kBytesWritten)]: 0
    [196] =>     },
    [197] =>     stdio: [ [Socket], [Socket], [Socket] ],
    [198] =>     [Symbol(kCapture)]: false
    [199] =>   },
    [200] =>   workStartTime: 1653576016735,
    [201] =>   ondone: [Function],
    [202] =>   workcount: 25,
    [203] =>   incoming: "SyntaxError: Expected token ')'\n" +
    [204] =>     '\n' +
    [205] =>     '  phantomjs://code/worker.js:658 in loop\n' +
    [206] =>     '{"filename":"tmp/pchart3.png"}',
    [207] =>   id: 1,
    [208] =>   doDone: [Function: doDone],
    [209] =>   restart: [Function],
    [210] =>   work: [Function],
    [211] =>   allowRestart: true
    [212] => }
    [213] => Thu May 26 2022 14:40:20 GMT+0000 (Coordinated Universal Time) [notice] phantom worker 1 - process was closed
    [214] => Thu May 26 2022 14:40:20 GMT+0000 (Coordinated Universal Time) [notice] terminating, killing all running phantom processes

Reproduction steps

Simply calling PHP exec with the highcharts conversion options above. ``` node -v v12.22.12 # The latest version would not generate anything on the cli export HIGHCHARTS_VERSION=9.1.0 && npm install highcharts-export-server -g --unsafe-perm ``` Even tried to get the experimental stuff working, but that fails as well. With its own errors. Regards, Jarrett
PaulDalek commented 2 years ago

Hi @jarrettj,

Sorry for the late reply. I tried to recreate the same behavior on my side but it looks like it works as intended. I've used the v9.1.0 of Highcharts as well as v12.22.12 of Node. As for the methods of exporting I used CLI and direct POST to the server. Chart exports correctly, take a look at the attached screenshot. Have you tried to call a raw CLI command without using PHP code?

#347

jarrettj commented 2 years ago

Hey man,

Thanks for the reply. We do not have the server setup. We don't POST anything.

Are you using the command line as follows:

highcharts-export-server -infile {$optionsFilename} -outfile {$chartFilename} --scale $scale --allowCodeExecution true

Could the functionality on the CLI and the server method be different? Thanks.

Regards, Jarrett

PaulDalek commented 2 years ago

Hi @jarrettj,

Yes, the same as above where the {$optionsFilename} is an object from your previous comment. As for your question, both CLI and sending POST use the same function to start exporting, only the way how data is gathered and organized is a little bit different. Try to reinstall the export server and use the newest version.

jszuminski commented 1 year ago

Closing due to inactivity.

I encourage you to try out our latest Puppeteer-based version of the Export Server (here’s a short setup guide: https://github.com/highcharts/node-export-server#puppeteer-version-information) where this should no longer be a problem.

If this issue still persists in the newest version, please report it again and we will investigate it.