I wish to add real time status update notification to a kohanaPHP application with MySQL database i'm developing using node.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.
Asked
Active
Viewed 951 times
2 Answers
1
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);

jfountain
- 3,715
- 2
- 24
- 22
-
With this kind of approach, could you actually push some data to the client ? – Pierre Nov 29 '12 at 12:33
0
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.

selfawaresoup
- 15,473
- 7
- 36
- 47
-
is there any example out there where i can get some inside how to do this data exchange Apache/PHP server with node? and how do i store the status the users post? am i to use node to store the data into the DB or PHP, thanks for the reply – Ebot Tabi Jul 03 '10 at 11:49
-
Well, node is a web server itself, so you can talk to it via HTTP requests. PHP can execute such requests. Node can, as of current versions, not access classic database systems like mysql. So. PHP has to do that. You just need to send the data to node via HTTP as soon as you store it into your DB. – selfawaresoup Jul 03 '10 at 13:36
-
There are a couple of MySQL modules available for Node.js now amongst others. Check out the database modules list here: http://wiki.github.com/ry/node/modules#database – Kynth Aug 11 '10 at 09:31
-
For examples, have a look at http://stackoverflow.com/questions/2353818/how-do-i-get-started-with-nodejs – lpfavreau Jan 04 '11 at 21:24