A simple node.js daemon on Laravel Forge crashes the server
I have a DigitalOcean server provisioned by Laravel Forge and I have a standard Laravel 8 application deployed to it.
I also setup a node.js based daemon using the Laravel Forge UI. Essentially, it listens to some web socket server and executes an artisan command, every 100ms or so.
This artisan command makes a few MySQL queries and some API calls.
Here is the node.js script:
const WebSocket = require('ws');
const { exec } = require("child_process");
const ws = new WebSocket('wss://some-url');
ws.on('open', function open() {
ws.send('{"op": "subscribe", "args": ["some-args"]}');
});
ws.on('message', function incoming(data) {
console.log('php ' + __dirname + '/artisan some:command --variable=' + data.variable);
exec('php ' + __dirname + '/artisan some:command --variable=' + data.variable);
});
Whenever I start this daemon, the CPU Load Average goes above 90%.
After a few minutes the server stops responding to the HTTP requests.
The server specs are: 4GB RAM - 2 CPU Cores - 80 GB SSD
I'd like some assistance figuring out what the problem is and how I can go about fixing it.
Please or to participate in this conversation.