简体   繁体   English

如何集成和安装node.js与在线服务器上运行的基于Codeigniter的Web应用程序?

[英]how to integrate and install node.js with codeigniter based web application running at online server?

I just have deployed my Codeigniter based application to the online server.Now I have need to add instant messaging like functionality using socket.io.Which is possible by installing node.js. 我刚刚将基于Codeigniter的应用程序部署到了在线服务器上,现在我需要使用socket.io添加即时消息之类的功能,这可以通过安装node.js来实现。 So how can I install node.js with codeigniter at online server. 因此,如何在在线服务器上使用codeigniter安装node.js。

You can run node as any other OS process. 您可以像运行任何其他OS进程一样运行节点。 There is a function in php ( exec ) which lets you run any shell command. php( exec )中有一个函数,可让您运行任何shell命令。

1) Install node on the server 1)在服务器上安装节点
2) Create a dir in your Code igniter project for your node scripts 2)在您的代码点火器项目中为节点脚本创建一个目录
3) Run the node scripts using the exec function, Something like this 3)使用exec函数运行节点脚本,就像这样

$node_output = "";
$exit_status = 0;
exec("node /var/www/myCIproject/nodescripts/sendMessages.js param1 param2", $node_output, $exit_status);
if ($exit_status == 0){ // in bash/node 0 means no errors
    echo "Messages sent succescully!";
}
else{ 
    echo "there was an error sending the messages";
}

Something like this will run the node process synchronously (which means that the php code will resume only after the node process has ended) and then it's gonna put the output of the node script in the second argument as a string ($node_output in the case) and the process status in the third one ($exit_status in our case) 这样的操作将同步运行节点进程(这意味着php代码将仅在节点进程结束后才恢复运行),然后将节点脚本的输出作为字符串放入第二个参数中(在这种情况下为$ node_output) )和第三个状态(本例中为$ exit_status)

Node scripts don't necessarily have to be inside the project, they can actually be anywhare in the server file system 节点脚本不一定必须在项目内部,它们实际上可以在服务器文件系统中使用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM