John
John

Reputation: 13739

Send Server Sent DOM event to specific IP with PHP

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.

Upvotes: 0

Views: 275

Answers (2)

John
John

Reputation: 13739

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);
?>

Upvotes: 1

marekful
marekful

Reputation: 15351

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.

Upvotes: 0

Related Questions