Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger a Node.js event from PHP

I have a PHP script running and supposedly I'd like to trigger Node.js firing an event to the client side when certain PHP logic has been fulfilled, how should I do it? The Node.js part is still yet to be set up, but will probably be on a different server other than the PHP/Apache one, and being put behind an Nginx which functions as a reverse proxy.

like image 502
gsklee Avatar asked Mar 23 '26 01:03

gsklee


2 Answers

Try:

<?php

$ch = curl_init();

$data = array('name' => 'Foo', 'file' => '@/home/user/test.png');

curl_setopt($ch, CURLOPT_URL, 'http://localhost:8000/'); /* Node app*/
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

curl_exec($ch);
?>

Review:

http://php.net/manual/en/function.curl-setopt.php

like image 194
alditis Avatar answered Mar 24 '26 14:03

alditis


You can connect with your php server to a node.js server, yes.

See the NodeLog Class on this page as an example,

http://gonzalo123.com/2011/05/09/real-time-monitoring-php-applications-with-websockets-and-node-js/

It's just a socket at the end of the day.

like image 33
shapeshifter Avatar answered Mar 24 '26 13:03

shapeshifter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!