node.js - How to spawn a new process in php to call a node script that requires a child process -


i'm trying run php code in isolation. php code calls node script @ intervals required arguments. node.js script on other hand computes arguments additional data mongodb , spawns child process within call phantomjs arguments , creates heatmap image file(s).

now node.js script runs fine when fired command line right arguments.

but no matter try i'm unable work when called php.

i have tried shell_exec , exec below:

$node = '/usr/local/bin/node'; $scriptpath = $this->basepath . '/web/scripts/node/heatmaps_node_wrapper.js'; $clickmapcmd = $node . ' ' . $scriptpath . ' ' . $url . ' ' . $groupid . ' ' . $heatmapid . ' click'; $mousemovemapcmd = $node . ' ' . $scriptpath . ' ' . $url . ' ' . $groupid . ' ' . $heatmapid . ' mousemove'; $asynccmd = ' >' . $this->basepath . '/logs/heatmap.io.log 2>'. $this->basepath . '/logs/heatmap.err.log &';  exec($clickmapcmd . $asynccmd); exec($mousemovemapcmd . $asynccmd); 

also tried using symfony's processbuilder component, -

$builder = new processbuilder(); $builder->setprefix('/usr/local/bin/node'); $builder->setarguments(array($scriptpath, $url, $groupid, $heatmapid, 'click')); $process = $builder->getprocess(); $process->settimeout(1000); $process->setidletimeout(1000); $process->start(); $output = $process->getoutput(); 

both fail create heatmap images.

but debugging symfony code , studying symfony's process object helped me discover problem. in objects stderr see following message -

events.js:85   throw er; // unhandled 'error' event         ^ error: spawn phantomjs enoent @ exports._errnoexception (util.js:746:11) @ process.childprocess._handle.onexit (child_process.js:1053:32) @ child_process.js:1144:20 @ process._tickcallback (node.js:355:11) 

so guess problem node trying create child process of, of php's child process(??).

so question is, solution (or work around) problem??

cheers!

the problem node can't find phantomjs. if it's not in $path user executing node script, may try using full path phantomjs binary. may want check executable permissions on phantomjs binary.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -