简体   繁体   English

如何将数据从node.js服务器传递到Apache服务的PHP页面?

[英]How to pass data from a node.js server to Apache served PHP page?

I am trying to build a node.js chat feature for an existing PHP project. 我正在尝试为现有的PHP项目构建一个node.js聊天功能。 I am using node.js socket.io for it. 我正在使用node.js socket.io。 Node.js is listening to port 3000. Now the problem is when I try to access the chat PHP page http://www.example.com:3000/app/chat.php the page gets downloaded instead of being served. Node.js正在侦听端口3000。现在的问题是,当我尝试访问聊天PHP页面http://www.example.com:3000/app/chat.php时,该页面将被下载而不是被提供。 I know that node.js does not serves PHP pages but what workaround can be done for the same? 我知道node.js不能提供PHP页面,但是可以为它做些什么解决方法?

Node.js Node.js的

var app = require('express')(),
        server = require('http').createServer(app),
        io = require('socket.io').listen(server),
        httpProxy = require('http-proxy');

server.listen(3000);

app.get('/', function (req, res) {
        res.sendfile(__dirname + '/index.php');
});

io.sockets.on('connection', function(socket) {
        socket.on('send data',function (data) {
                io.sockets.emit('latest data',data);           
        });
});

PHP PHP

<?php

// Blah Blah

<script>
                        jQuery(function($))
                        {
                                var socket = io.connect();
                                var $editArea = $('#editAreaID');

                                $editArea.keydown(function(){
                                        socket.emit('send data', $editArea.val());
                                });

                                socket.on('latest data', function(data){
                                        $editArea.val(data);
                                });
                        }
</script>

// Blah Blah

?>

If your PHP page is being downloaded instead of running normally then it has probably nothing to do with the node.js server. 如果您的PHP页面正在下载而不是正常运行,则它可能与node.js服务器无关。

Verify first that PHP is installed correctly and that the PHP module is enabled in the apache configuration. 首先验证是否正确安装了PHP,并且已在apache配置中启用了PHP模块。

See https://serverfault.com/questions/215455/what-causes-php-pages-to-consistently-download-instead-of-running-normally 参见https://serverfault.com/questions/215455/what-c​​auses-php-pages-to-consistently-download-instead-of-running-normally

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

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