运行 来自 php shell_exec() 的节点 js
Run node js from php shell_exec()
您好,我上传了一些要解析的文件,这些文件由 node js
解析。目前我是 运行 从终端作为 node app.js
.
我需要从我的 php 模型中调用它。
我认为 shell_exec()
功能会有所帮助。我试过这样
shell_exec('http://172.18.18.219/hrms_work/web/uplodedfiles/test/code4goal-resume-parser/app.js');
但它不起作用。
您没有执行任何命令,这就是它不起作用的原因。 shell_exec()
完全按照您在终端中编写的内容进行操作,这样效果会更好 shell_exec('node app.js')
。但是您还必须 cd
到正确的目录或提供到 app.js
的绝对路径。您正在使用 url 到 app.js
,我不确定 node
是否可以 运行 这样的远程文件。
- 你的
shell_exec()
论点是错误的。这个论点在你的终端上有效吗?可能不是因为是一个简单的 link.
- 您的文件
app.js
是否具有 运行 Apache 用户的正确权限?
回答完这些问题后,请确保您在 shell_exec()
中输入了正确的参数:app.js
的绝对路径以及您在终端中使用的相同命令,我认为是 node app.js
。
有点像
shell_exec(node /absolute/path/to/app.js);
请告诉我们 ;)
您好,我上传了一些要解析的文件,这些文件由 node js
解析。目前我是 运行 从终端作为 node app.js
.
我需要从我的 php 模型中调用它。
我认为 shell_exec()
功能会有所帮助。我试过这样
shell_exec('http://172.18.18.219/hrms_work/web/uplodedfiles/test/code4goal-resume-parser/app.js');
但它不起作用。
您没有执行任何命令,这就是它不起作用的原因。 shell_exec()
完全按照您在终端中编写的内容进行操作,这样效果会更好 shell_exec('node app.js')
。但是您还必须 cd
到正确的目录或提供到 app.js
的绝对路径。您正在使用 url 到 app.js
,我不确定 node
是否可以 运行 这样的远程文件。
- 你的
shell_exec()
论点是错误的。这个论点在你的终端上有效吗?可能不是因为是一个简单的 link. - 您的文件
app.js
是否具有 运行 Apache 用户的正确权限?
回答完这些问题后,请确保您在 shell_exec()
中输入了正确的参数:app.js
的绝对路径以及您在终端中使用的相同命令,我认为是 node app.js
。
有点像
shell_exec(node /absolute/path/to/app.js);
请告诉我们 ;)