Question

I have a PHP cron job that checks for new emails once every minute. I can fetch the IP addresses for every account from my database via the authentication log no problem. What I'm not sure about is how to send the Server Sent DOM event to specific IP addresses.

The basic...

<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
$ip = '127.0.0.1';
$message = 'Example Message.';
?>

This is NOT something that can be initiated from the client at all since it is a cron job. It is perfectly okay if one/any/all account holders don't have a browser open and ready to accept the notification, they are aware of that requirement.

This question is explicitly how to send a signal from the server to the client and has nothing to do with the client other then sending a signal to their IP address.

Was it helpful?

Solution

I just have to use fsockopen()...

<?php
header('Content-Type: text/event-stream');
header('Cache-Control: no-cache');
$ip = '127.0.0.1';
$message = 'Example Message.';
$result1 = fsockopen($ip,80,200,$message,30);
?>

OTHER TIPS

You cannot initiate any communication from a web server to a client. The client must first send a request in response to which your server may send the required information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top