How can NodeJS be integrated with PHP for real-time events?

To integrate NodeJS with PHP for real-time events, you can use a messaging system like Redis or RabbitMQ to facilitate communication between the two technologies. NodeJS can listen for events and PHP can publish events to the messaging system, allowing for real-time communication between the two.

// PHP code snippet to publish an event to Redis
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
$redis->publish('realtime_events', json_encode(['event' => 'new_message', 'data' => 'Hello from PHP']));