开发者

how to integrate node.js into a kohanaPHP application for real time status update notification

I wish to add real time status update notification to a kohanaPHP application with MySQL database i'm developing using nod开发者_Python百科e.js, while looking around, i could not find any tutorials about integrating node.js in PHP, i will like to know if its possible and how can it be done and what type of servers should i host the php website on. From what i got its seems node.js does not work on Apache servers. i'll be grateful for help.


Node is it's own server so what you want to do is make a request to the node.js application. You can do this with Curl. One other way is to use Kohana's HMVC feature to make an external request. This example assumes your node.js app returns json.

 //Make an external request using post.
$json_request = Request::factory('http://www.example.com/path/to/nodejs')
        ->method('POST')
        ->post('my_key', 'value')
        ->headers('Accept','application/json')
        ->execute();

//Get the json from the request.
$json_string = $json_request->body();

//Turn the json string into an array.
$json_array = json_decode($json_string);

//Take a look at it with debug.
echo Debug::vars($json_array);


First: You don't run node in any Apache or other web server. It's its own server. So you need to implement data exchange between your Apache/PHP server and node.

You can call your node program via a HTTP request from PHP as soon as something changes and push the new data into your node.

That way you don't need access to MySQL for node, which is not available yet anyway.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜