Answer the question
In order to leave comments, you need to log in
How to make friends backend wordpress and node pm2?
Good day, colleagues!
There is wordpress, there is node pm2. They work on the same host. I would like to restart a certain task in pm2 when clicking in the wordpress admin panel.
Tried the trail. option:
1. Send ajax request to php part of wp.
2. php, having received this request, tried to execute it like this:
shell_exec('node /home/cron/tempTask.js'); // process is restarted in tempTask.js via require('pm2').
and so:
shell_exec('pm2 start TempTask');
The maximum that was achieved was to receive in response the standard output of pm2:
Community Edition
Production Process Manager for Node.js applications
with a built-in Load Balancer.
Start and Daemonize any application:
$ pm2 start app.js
Load Balance 4 instances of api.js:
$ pm2 start api.js -i 4
Monitor in production:
$ pm2 monitor
Make pm2 auto-boot at server restart:
$ pm2 startup
To go further checkout:
pm2.io
Task in pm2 does not restart.
Any ideas in which direction to dig? Maybe someone has already encountered.
Answer the question
In order to leave comments, you need to log in
Most likely the problem is that pm2 keeps its own list of tasks for each system user, and you probably run php from a different user from the one under which the necessary pm2 tasks are running.
As a head-on solution, I would suggest rolling out a small service on a node, which will be launched from under the desired user by the same pm2 and will listen to a unix socket (do not forget to give the right to issue a current) or port, and with php just pull it with requests
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question