Run server-side js from php through exec()

≯℡__Kan透↙ 提交于 2020-01-01 18:57:30

问题


I have a site running on Apache/PHP, and as a matter of performance, I wrote a javascript to do a specific task.

I have installed node.js on server, in order to run this javascript. When I call the script from the command line, it works fine. See the command below:

> node myscript.js

But I need it to run from a php page, and I am trying to do this by calling the exec() PHP function, like this:

<?php exec('node myscript.js >/dev/null/ 2>&1 &'); ?>

...but it's not working.

Am I doing something wrong? Is there another way to do what I want?


回答1:


I found a way to make it work! I just wrote the full directory where node.js is installed in the exec() call. Simple as that:

<?php exec('/home/bin/node myscript.js >/dev/null/ 2>&1 &'); ?>


来源:https://stackoverflow.com/questions/17180656/run-server-side-js-from-php-through-exec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!