I use the follow code to run a PHP script in CLI environment within a nodejs daemon.
The script takes the data in stdin performs the calculations and return other data to stdout.
The problem is that to run the script with child_process.spawn and pipes to an increasing memory usage. So I must to restart the node app every little time.
I would like to keep constant the use of RAM.
In the example I use cat command to simulate my php script, but the problem persists, increasing use of memory proportional to the number of cycles in setInterval. And I use setInterval to simulate period execution of the script.
var spawn = require('child_process').spawn;
var php = spawn('cat');
php.stdout.pipe(process.stdout);
var i = 0;
setInterval(function() {
php.stdin.write(++i);
},10);php.stdout.pipe(process.stdout);
On May 22, 2014, at 8:08 PM, Stefano Cudini <stefano...@gmail.com> wrote:php.stdout.pipe(process.stdout);This doesn’t make sense to me, that you are piping the stdout of the “php” process to your own stdout.
Did you mean to pipe your stdout to php’s stdin? I have always found Node’s Streams stuff complicated or non-intuitive…
Regards,—ravi
after various tests suggested here:
https://github.com/joyent/node/issues/7666
the problem persists .... with time... increases the memory used by node!
Even if I kill the spawn process(into loop), or if it's auto terminated with exit
On each new execution the memory required to process node also increases imposed if the variables "--expose-gc --always-compact"
is there a way to limit the memory used by node??
my server has only 1GB of ram, help!